I have a macro that I created to subtotal and format the sheet in a specific way. I'm trying to create a loop so that this macro will run on all remaining tabs in my workbook, but it's only completing this on the first tab and nothing happens with the rest. Can someone help to understand what's wrong with my code? The number of tabs in the workbook can vary, however, the "All Stores" tab is consistent and is the only tab that should be excluded. Here's what I have so far:
Sub MovethroughWB() 'Excel VBA to exclude All Stores from the loop.
Dim ws As Worksheet
For Each ws In Sheets
If ws.Name <> "All Stores" Then
Rows("2:2").Select
ActiveWindow.FreezePanes = True
Cells(1, 1).Select
Selection.Subtotal GroupBy:=10, Function:=xlSum, TotalList:=Array(12), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
ActiveWindow.SmallScroll Down:=-3
End If
Next ws
End Sub
The indented rows are the first macro I wrote, and when I run that macro it works great. I then tried to create the loop so that the same macro could be run on the rest of the worksheets in the workbook. However, each time I run it, it still only runs the macro on the sheet I'm on. I'm new to looping, so any help you can provide would be greatly appreciated. What I've done thus far is simply what I found on other sites trying to learn how to loop. Clearly I'm missing something.
Sub MovethroughWB() 'Excel VBA to exclude All Stores from the loop.
Dim ws As Worksheet
For Each ws In Sheets
If ws.Name <> "All Stores" Then
Rows("2:2").Select
ActiveWindow.FreezePanes = True
Cells(1, 1).Select
Selection.Subtotal GroupBy:=10, Function:=xlSum, TotalList:=Array(12), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
ActiveWindow.SmallScroll Down:=-3
End If
Next ws
End Sub
The indented rows are the first macro I wrote, and when I run that macro it works great. I then tried to create the loop so that the same macro could be run on the rest of the worksheets in the workbook. However, each time I run it, it still only runs the macro on the sheet I'm on. I'm new to looping, so any help you can provide would be greatly appreciated. What I've done thus far is simply what I found on other sites trying to learn how to loop. Clearly I'm missing something.