Good day friends,
I'm receiving an error whenever I try to loop through all open workbooks in order to copy and paste to a master workbook.
For the life of me I can't figure out how to rectify it, could any of you kindly assist?
Sub LoopCopyPaste()
Dim wb As Workbook
Dim Lastrow As Long
For Each wb In Application.Workbooks
If wb.Name <> "MasterDatabase.xlsx" & "MacrosExcelFile.xls" Then
Lastrow = wb.Worksheets(1).Cells(Rows.Count, 2).End(xlUp).Row
wb.Worksheets(1).Range("B7:J" & Lastrow).Copy
''
Windows("MasterDatabase.xlsx").Activate
Range("B" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
End If
Next wb
End Sub
The error is "1004, Application-defined or object-defined error", and it points to the "Lastrow = wb.Worksheets(1).Cells(Rows.Count, 2).End(xlUp).Row" sentence.
What can I do to solve this issue?
Thanks in advance.
No comments:
Post a Comment