Results 1 to 2 of 2

Thread: VBA code to create sheet in new workbook and rename it

  1. #1

    VBA code to create sheet in new workbook and rename it



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi,
    i'm seeking for a vba code for my following issue
    .
    the code does match this cell value from oldworkbook with all the sheetnames in the newworkbook, if it finds the sheetname that matches value, it copies a range F1 to H1 in its cell A1, else it create a new sheet and rename it with the cell value and paste the range.
    any help on it is greatly appreciated

    my code is
    Code:
     
    Option Explicit
    Sub copyDataToClosedWorkbook()
        Dim wbTo   As Workbook
        Dim wbFrom As Workbook
        Set wbFrom = ActiveWorkbook
        Set wbTo = Workbooks.Open("C:\Project\Final.xlsm", _
                                  False, True)
        With wbFrom
        wbFrom.Sheets("ratios").Range("k1:Aj6").Copy
        End With
        
        Application.ScreenUpdating = False
        With wbTo
        wbTo.Sheets("Sheet1").Name = wbFrom.Sheets("webquery").Range("A1").Value.Activate
        ActiveSheet.Range("A1").PasteSpecial Paste:=xlValues, Transpose:=True
        Worksheets.Add().Name = ("sheet1")
    End With
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        wbTo.ChangeFileAccess Mode:=xlReadWrite
        wbTo.Close SaveChanges:=True
    End Sub

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,195
    Articles
    57
    Blog Entries
    14
    Hi fari, and welcome to the forum.

    I'm not sure I quite follow you... your code doesn't seem to follow along the lines of your goal. Could you:
    -Explain again, step by step, what you'd expect the macro to do
    -Upload two workbooks of simple data and tell us what information from book1 you'd like copied to book2?
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Master your data with Power Query: Purchase your copy of my book M is for Data Monkey today!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •