我想在我的所有工作表中运行以下代码。我有大约20张。我错过了什么?
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
答案 0 :(得分:2)
试试这个:
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