fari1
Active Member
- Joined
- May 29, 2011
- Messages
- 362
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
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