Hi, i'm trying to write some VBA code to open several workbooks, copy a column, and past into the book I run the macro from. I need the data I copy over to all go into the same column. Here is my code:
The first problem I have here, is if one of the source books is open when I run the code from the report book, it won't copy & paste into the report book. Instead it pastes into that open source book, and I don't know why. I've assigned my report book to 'x' and only 'x' is used for pasting. Can anyone shed any light on why this would happen?
Code:
Sub MeToo_Paste()
'Assign Report Book
Dim x As Workbook
'Assign Source Books
Dim y As Workbook
Dim z As Workbook
'Open Report Book
Set x = Workbooks.Open("C:\Filepath\Documents\Report.xlsm")
'Open Source Books
Set y = Workbooks.Open("C:\Filepath\Documents\Source 1.xlsx")
Set z = Workbooks.Open("C:\Filepath\Documents\Source 2.xlsx")
'Copy & Paste 1
y.Sheets("Sheet1").Range("B2:B500").Copy
x.Sheets("Sheet1").Range("B2").PasteSpecial
'Copy & Paste 2
z.Sheets("Sheet1").Range("B2:B500").Copy
x.Sheets("Sheet1").Range("B2").End(xlDown).Offset(1, 0).PasteSpecial
'Close
y.Close
z.Close
End Sub
The first problem I have here, is if one of the source books is open when I run the code from the report book, it won't copy & paste into the report book. Instead it pastes into that open source book, and I don't know why. I've assigned my report book to 'x' and only 'x' is used for pasting. Can anyone shed any light on why this would happen?