Hi
Is there a way to loop through a list of tabs individually ? i want to add subtotals to certain sheets, i know it is not possible to add subtotals to multilple sheets at once so i want the macro to loop though the sheets idividually.
so far i have, but this errors at the subtotal
sub macro_x()
Dim MyTab As Object
Dim LastRow As String
Sheets("TY COMPANY SUM").Select
LastRow = Range("B4").End(xlDown).Row
'Add grage lookup, sort and add subtotals to the TY COMPANY SUM
Sheets(Array("TY COMPANY SUM", "LY COMPANY SUM")).Select
For Each MyTab In ActiveWindow.SelectedSheets
MyTab.Activate
Range("D5").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-2],LFL!R4C1:R1000C3,3,0)"
Selection.AutoFill Destination:=Range("D5:D" & LastRow), Type:=xlFillDefault
Columns("D:D").SpecialCells(xlCellTypeFormulas, 16).EntireRow.Delete
Range("D5").Select
Range("B4:F568").Sort Key1:=Range("D5"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Selection.Subtotal GroupBy:=3, Function:=xlSum, TotalList:=Array(4, 5), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
Next mytab
End Sub
Is there a way to loop through a list of tabs individually ? i want to add subtotals to certain sheets, i know it is not possible to add subtotals to multilple sheets at once so i want the macro to loop though the sheets idividually.
so far i have, but this errors at the subtotal
sub macro_x()
Dim MyTab As Object
Dim LastRow As String
Sheets("TY COMPANY SUM").Select
LastRow = Range("B4").End(xlDown).Row
'Add grage lookup, sort and add subtotals to the TY COMPANY SUM
Sheets(Array("TY COMPANY SUM", "LY COMPANY SUM")).Select
For Each MyTab In ActiveWindow.SelectedSheets
MyTab.Activate
Range("D5").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-2],LFL!R4C1:R1000C3,3,0)"
Selection.AutoFill Destination:=Range("D5:D" & LastRow), Type:=xlFillDefault
Columns("D:D").SpecialCells(xlCellTypeFormulas, 16).EntireRow.Delete
Range("D5").Select
Range("B4:F568").Sort Key1:=Range("D5"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Selection.Subtotal GroupBy:=3, Function:=xlSum, TotalList:=Array(4, 5), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
Next mytab
End Sub