I have a workbook with 10 worksheets, 6 of which need to be consolidated into a single worksheet. Those 6 all have the same header row. I can get my code to work some of the time. However, if one of the worksheets is empty (only has the header row), the header will be copied to the new consolidated sheet.
I have tried adding an "On Error Resume Next", which only prevents an error from being generated. It still only copies the header row.
Sub Combine()
Dim s As Worksheet
On Error Resume Next
Application.DisplayAlerts = False
Sheets("All").Delete 'These sheets don't need to be kept or consolidated
Sheets("005").Delete
Sheets("006").Delete
Sheets("007").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Sheets(1).Select
Worksheets.Add
Sheets(1).Name = "0"
Sheets(2).Activate
Range("A1").EntireRow.Select
Selection.Copy Destination:=Sheets(1).Range("A1")
For Each s In ActiveWorkbook.Sheets
If s.Name <> "0" Then
Application.GoTo Sheets(s.Name).[a1]
Selection.CurrentRegion.Select
'On Error Resume Next
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Copy Destination:=Sheets("0"). _
Cells(Rows.Count, 1).End(xlUp)(2)
'On Error GoTo 0
End If
Next
End Sub
I need to have the macro copy only filled rows below the header and skip over any sheets that happen to be blank.