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!

    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
    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
        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
    Nanaimo, BC, Canada
    Blog Entries
    Excel Version
    Excel Office 365 Insider
    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

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: -||- Blog: -||- 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