In short, there is something wrong with the line
Sheets("Sheet2").Range(Cells(b, 1), Cells(b, 7)).Copy Sheets("Sheet1").Cells(a, 6)
change it into the below should fix your problem.
Sheets("Sheet2").Range(Sheets("Sheet2").Cells(b, 1), Sheets("Sheet2").Cells(b, 7)).Copy Sheets("Sheet1").Cells(a, 6)
How did I debug:
When your code is run, click "Debug" when the runtime error 1004 pop up. The 4th line is highlighted in yellow (i.e. VBA encounters error running that line). So that's where we start.
To eliminate problem, we can move the cursor over various variables to look at its value. b
= 7, a
= 8, seems fine.
Removing the parameters for Copy
function, leaving only everything before the .Copy
... the problem is still there. So there should be something wrong with
Sheets("Sheet2").Range(Cells(b, 1), Cells(b, 7)).Copy
Looking at help on .Range
and note that you need to specify the Sheet
as well. And the problem is fixed.