Hi I have code which is meant to
- Loop through all worksheets which begin with "673"
- Copy all the rows which have data from row 5 onwards
- Paste the entries on the next empty row in the "Colours" worksheet
I'm having the following issues:
- Code only runs in the worksheet that is active
- Doesn't loop through all worksheets
When it pastes in the "Colours" worksheet, it pastes directly over the headings in row 2. The first blank row is row 3 onwards and I would like the logic to paste at the next available blank row as it loops through the sheets.
Sub Consolidate() Dim lastrow As Long Dim report As Worksheet Set report = Excel.ActiveSheet For Each Sheet In ActiveWorkbook.Worksheets If InStr(Sheet.Name, "673") > 0 Then With report .Range(.Cells(5, "K"), .Cells(.Rows.Count, "K").End (xlUp)).EntireRow.Copy End With Worksheets("Colours").Select lastrow = Worksheets("Colours").Cells(Worksheets("Colours").Rows.Count, 1).End(xlUp).Row Worksheets("Colours").Cells(lastrow + 1, 1).Select ActiveSheet.Paste End If Next End Sub
Your help would be greatly appreciated.
With report
should beWith sheet
. try this – Rosetta