Good Afternoon
I'm compiling a monthly report, adding data monthly to make it YTD. I have one to two sheets per month with the data which I'm adding every month. I then analyse the data with a Pivot Table.
I have a macro that combines all sheets in a workbook but need to find a way to tell the macro to leave specific sheets out. Else I either need to recreate the Pivot Table each month, or combine the data manually.
I first thought by hiding the sheet the macro would ignore the sheets but that doesn't work. Then I thought that maybe I could tell it to only combine the visible sheets. But my code isn't right. When stepping through my code, it also doesn't realibly hide the sheets and I have no idea why that would be.
Thanks for any ideas. Maybe there is another property that could define which sheets should be combined?
Public Sub CombineSheets()
Dim ws As Worksheet
Dim wsPivot As Worksheet
Dim wsTeams As Worksheet
On Error Resume Next
Set wsPivot = ActiveWorkbook.Sheets("Pivot")
Set wsTeams = ActiveWorkbook.Sheets("Teams")
wsPivot.Visible = xlSheetVeryHidden
wsTeams.Visible = xlSheetVeryHidden
Worksheets(1).Activate
Dim J As Integer
Sheets(1).Select
Worksheets.Add
Sheets(1).Name = "Combined"
If Sheets(2).Visible = True Then
Sheets(2).Activate
Range("A1").EntireRow.Select
Selection.Copy Destination:=Sheets(1).Range("A1")
End If
If Sheets(J).Visible = True Then
For J = 2 To Sheets.Count
Sheets(J).Activate
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Copy Destination:=Sheets(1).Range("A65536").End(xlUp)(2)
Next
End If
wsPivot.Visible = xlSheetVisible
wsTeams.Visible = xlSheetVisible
End Sub
Display More