clairecatx
New Member
- Joined
- Aug 9, 2024
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Hello. I attempted to create a macro that copies data from multiple sheets and paste as values in a 'master' sheet, with the data from each sheet stacked without overlaps in the master sheet. Order is not important. All within the same workbook. When I run the code from Project Explorer, it works fine. But when I try to do so through a button, I get this error:
I've also experienced similar issues running the script multiple times in the same session through Project Explorer. However, the first time is usually fine.
Here's the code:
Sub Collate_Transactions_v4()
'4. Collate latest transactions (Mod 3)
Dim a As Workbook
Set a = ThisWorkbook
Set ws1 = a.Sheets("Sheet1")
Set ws2 = a.Sheets("Sheet2")
Set ws3 = a.Sheets("Sheet3")
...
Set ws9 = a.Sheets("Master")
ws1.Range("A2:C" & Range("A2").End(xlDown).Row).Copy
ws9.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
ws2.Range("A2:C" & Range("A2").End(xlDown).Row).Copy
ws9.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
ws3.Range("A2:C" & Range("A2").End(xlDown).Row).Copy
ws9.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End Sub
Here's a screenshot of where it gets stuck:
Anyone know what the issue is and what needs tweaked?
Kind regards,
Claire
I've also experienced similar issues running the script multiple times in the same session through Project Explorer. However, the first time is usually fine.
Here's the code:
Sub Collate_Transactions_v4()
'4. Collate latest transactions (Mod 3)
Dim a As Workbook
Set a = ThisWorkbook
Set ws1 = a.Sheets("Sheet1")
Set ws2 = a.Sheets("Sheet2")
Set ws3 = a.Sheets("Sheet3")
...
Set ws9 = a.Sheets("Master")
ws1.Range("A2:C" & Range("A2").End(xlDown).Row).Copy
ws9.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
ws2.Range("A2:C" & Range("A2").End(xlDown).Row).Copy
ws9.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
ws3.Range("A2:C" & Range("A2").End(xlDown).Row).Copy
ws9.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End Sub
Here's a screenshot of where it gets stuck:
Anyone know what the issue is and what needs tweaked?
Kind regards,
Claire