我试图清除工作簿中多个数据透视表上的所有过滤器(在多个工作表上)。我尝试过以下方法,但无法正常工作。
我对VBA FYI来说相对较新。
Sub ClearFiltersAttempt1()
For Each xWs In Application.ActiveWorkbook.Worksheets
For Each xTable In xWs.PivotTables
xPivotField.ClearAllFilters
End Sub
答案 0 :(得分:0)
2个For Each
语句缺少结束语句Next
Option Explicit
Public Sub ClearFiltersAttempt2()
Dim ws As Worksheet, pt As PivotTable
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.ClearAllFilters
Next
Next
End Sub
Option Explicit
和正确的代码缩进将帮助您确定语法错误和缺少变量声明