Pinkster69
New Member
- Joined
- Jun 19, 2012
- Messages
- 48
Hi Guys,
I know that there have been threads about this but for the life of me I cannot seem to find anything that will help me to copy a range in multiple worksheets in different workbooks and paste them into different worksheets in the active workbook.
I have code that will copy a range in a worksheet and paste it into another worksheet in a different workbook, this all works well but I really need some expertise to help me modify my code as my knowledge is limited.
I have attached a copy of my code for more clarity.
Thanks in advanced guys
I know that there have been threads about this but for the life of me I cannot seem to find anything that will help me to copy a range in multiple worksheets in different workbooks and paste them into different worksheets in the active workbook.
I have code that will copy a range in a worksheet and paste it into another worksheet in a different workbook, this all works well but I really need some expertise to help me modify my code as my knowledge is limited.
I have attached a copy of my code for more clarity.
Thanks in advanced guys
Code:
Sub foo()
Dim x As Workbook
Dim y As Workbook
'## Open both workbooks:
Set x = Workbooks.Open("C:\Users\HQ\Downloads\vend-sales-by-hour-42233.csv") 'Workbook where worksheet is to be copied
Set y = Workbooks.Open("C:\Users\HQ\Documents\VBA Code\Forum Questions & Test Code\Test Code\Worksheet Codes\Final Destination.xlsm") 'Workbook where the copied worksheet is to be pasted
'Worksheet Copied from x:
x.Sheets("vend-sales-by-hour-42233").Range("A:Z").Copy
'Paste copied worksheet to y worksheet "Destination"
y.Sheets("First Destination").Range("A:Z").PasteSpecial
ActiveWorkbook.Saved = True
Application.CutCopyMode = False
'Close x & y:
x.Close
y.Close
End Sub