vba 如何在数据透视表过滤器中选择(全部)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23793680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to select (All) in a pivot table filter
提问by Buras
I need (All)
to be selected in my pivot table
我需要 (All)
在我的数据透视表中被选中
I tried the following
我尝试了以下
Dim pf As PivotField
Set pf = Worksheets("xxx").PivotTables("PivotTable1").PivotFields("myFilterField")
For Each Pi In pf.PivotItems
Pi.Visible = True
Next Pi
This works very slowly, and not well
这工作非常缓慢,而且效果不佳
Another option does not work at all . It selects only some of the items that were selected previously
另一种选择根本不起作用。它只选择之前选择的一些项目
Worksheets("xxx").PivotTables("PivotTable1").PivotFields("myFilterField").CurrentPage = "(All)"
回答by Cor_Blimey
You could be calling .Visible = True for a couple of reasons so hopefully one of the below covers what you are trying to do:
您可能会出于多种原因调用 .Visible = True ,因此希望以下其中一项涵盖您要执行的操作:
If you mean you want to set all the Pi to be visible in one step then rather than enumerating through the Pi in pf.PivotItems just:
如果您的意思是要在一个步骤中将所有 Pi 设置为可见,那么只需在 pf.PivotItems 中枚举 Pi:
pf.ShowAllItems = True
pf.ShowAllItems = True
If, on the other hand, you mean you want clear all filters then:
另一方面,如果您的意思是要清除所有过滤器,则:
pf.ClearAllFilters()
pf.ClearAllFilters()
Or, if you want to just clear manual filters (i.e. not filters applied against an actual row/column filed but rather against a filter field) then:
或者,如果您只想清除手动过滤器(即不是应用于实际行/列的过滤器,而是应用于过滤器字段),则:
pf.ClearManualFilters
pf.ClearManualFilters
Consult help on PivotField Object Members for the full list
有关完整列表,请参阅有关 PivotField 对象成员的帮助
回答by Pinang
Try the below code:
试试下面的代码:
Worksheets("xxx").PivotTables("PivotTable1").PivotFields("myFilterField").ClearAllFilters