I am trying to go through each worksheet in the active workbook in which the sheets are created as part of a macro that is working. The names can be different each time, so I can't just do a lookup. I want to take one piece of information (same cell on each worksheet) and paste it into the next empty cell in a column on another sheet.
At line 6 I get the error subscript out of range error 9. I've checked the naming of the sheet I am pasting to and it is correct. No extra spaces.
It's driving me nuts. Can you help?
ps I am working on this to run on a MAC which I normally don't do, so maybe I have the code slightly wrong.
For Each sh In ThisWorkbook.Worksheets
DoEvents
sh.Activate
Range("K5").Select
Selection.Copy
Sheets("Payment Ref").Range("b2").Select
If Range("b2") = "" Then
Range("b2").PasteSpecial Paste:=xlPasteFormats
Range("b2").PasteSpecial Paste:=xlPasteValues
Else
Range("b2").Offset(1, 0).PasteSpecial xlPasteFormats
Range("b2").Offset(1, 0).PasteSpecial xlPasteValues
End If
Next sh
At the end of the run the Payment Ref Spreadsheet should have a column filled with invoice numbers from the invoice sheets created in the previous macro section. This works perfectly.