VBA code to create sheet in new workbook and rename it

fari

New member
Joined
May 29, 2011
Messages
1
Reaction score
0
Points
0
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
 
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?
 
Back
Top