Copy data from multiple sheets into a master sheet - VBA button stuck

clairecatx

New Member
Joined
Aug 9, 2024
Messages
4
Office Version
  1. 365
Platform
  1. 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:

1730116082215.png


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:

1730116790262.png


Anyone know what the issue is and what needs tweaked?

Kind regards,
Claire
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi Claire. I think your missing the bold parts below. Using Resize would be better than copy/paste. HTH. Dave
ws1.Range("A2:C" & ws1.Range("A2").End(xlDown).Row).Copy
ws9.Cells(ws9.Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
 
Upvote 0
Solution
You are welcome. To speed things up after each copy/paste, you should also include the line...
VBA Code:
Application.CutCopyMode = False
To avoid copy/paste using resize...
VBA Code:
Dim Rng As Range
Set Rng = ws1.Range("A2:C" & ws1.Range("A2").End(xlDown).Row)
ws9.Cells(ws9.Rows.Count, 1).End(xlUp).Offset(1, 0).Resize(Rng.Rows.Count, _
            Rng.Columns.Count).Cells.Value = Rng.Cells.Value
Thanks for posting your outcome. Dave
 
Upvote 0

Forum statistics

Threads
1,223,868
Messages
6,175,084
Members
452,611
Latest member
bls2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top