Reputation: 1
I want to make the following code run throughout all my sheets. I have about 20 sheets. What am i missing?
Sub Filter1()
Dim wSheet As Worksheet
Dim i As Long
For i = 0 To ActiveWorkbook.Worksheets.Count
ActiveSheet.Range("$Q$1:$Q$90").AutoFilter Field:=1, Criteria1:="<>"
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1
ActiveSheet.Select
Next i
End Sub
Upvotes: 0
Views: 52
Reputation: 117164
Try this:
Sub Filter1()
Dim i As Integer
For i = 1 To ThisWorkbook.Worksheets.Count
ThisWorkbook.Worksheets(i).Range("$Q$1:$Q$90").AutoFilter Field:=1, Criteria1:="<>"
ThisWorkbook.Worksheets(i).Outline.ShowLevels RowLevels:=0, ColumnLevels:=1
Next i
End Sub
Upvotes: 3