Sub 透视筛选(pf, pv, v)
With ActiveSheet.PivotTables("数据透视表1").PivotFields(pf)
.EnableMultiplePageItems = True
For Each pii In .PivotItems '全部选中以免出现全不选错误
pii.Visible = True
Next
For Each pii In .PivotItems
If IsError(Application.Match(pii.Name, pv, 0)) Then
pii.Visible = Not (v) '不存在
Else
pii.Visible = v '存在
End If
Next
End With
End Sub
调用例子:
Call 透视筛选("层数", Array("all"), False) '全部选中
Call 透视筛选("储位编码", Array("AA52"), True)
网友评论