I've see several posts with vba codes to combine all sheets in a workbook into one sheet or select certain sheets based on sheet name or by identifying sheets x to y, but cannot find how to combine sheets from sheet 7 and greater.
I want to combine all sheets in my file to a "Summary" starting with sheet 7 and the number of sheets beyond 7 can vary it could be 4 additional sheets or 20 additional sheets. The sheet names vary each time so I cannot use that.
This is what I have currently which specifies I want to combine data from Sheet7 to Sheet9. If I only have up until sheet 9 in my file and if I try to overachieve in the code to say 7 to 20, the data from sheet 9 will duplicate the additional 11 times which is why this won't work.
Sub Summary()
Dim J As Integer
Dim s As Worksheet
' Add a sheet in first place
On Error Resume Next
Sheets(1).Select
Worksheets.Add
Sheets(1).Name = "Summary"
' Copy headings
Sheets(7).Activate
Range("A1").EntireRow.Select
Selection.Copy Destination:=Sheets(1).Range("A1")
'This is to combine the range of identified worksheets
Dim Cnt
For Cnt = 7 To 9
Application.Goto Worksheets.Item(Cnt).[A1]
Selection.CurrentRegion.Select
' Don't copy the headings
Selection.Offset(2, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Copy Destination:=Sheets("Summary"). _
Cells(Rows.Count, 1).End(xlUp)(2)
Next Cnt
End Sub
Hoping someone can help!
I want to combine all sheets in my file to a "Summary" starting with sheet 7 and the number of sheets beyond 7 can vary it could be 4 additional sheets or 20 additional sheets. The sheet names vary each time so I cannot use that.
This is what I have currently which specifies I want to combine data from Sheet7 to Sheet9. If I only have up until sheet 9 in my file and if I try to overachieve in the code to say 7 to 20, the data from sheet 9 will duplicate the additional 11 times which is why this won't work.
Sub Summary()
Dim J As Integer
Dim s As Worksheet
' Add a sheet in first place
On Error Resume Next
Sheets(1).Select
Worksheets.Add
Sheets(1).Name = "Summary"
' Copy headings
Sheets(7).Activate
Range("A1").EntireRow.Select
Selection.Copy Destination:=Sheets(1).Range("A1")
'This is to combine the range of identified worksheets
Dim Cnt
For Cnt = 7 To 9
Application.Goto Worksheets.Item(Cnt).[A1]
Selection.CurrentRegion.Select
' Don't copy the headings
Selection.Offset(2, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Copy Destination:=Sheets("Summary"). _
Cells(Rows.Count, 1).End(xlUp)(2)
Next Cnt
End Sub
Hoping someone can help!