调整枢轴表的过滤器
我正在尝试根据预定的设置调整枢轴表的过滤器。
我想清除所有枢轴表滤波器,然后选择过滤器。
代码给了我
运行时错误'1004':无法设置Pivotfield类的PivotItems属性。
它也无法清除枢轴表上的过滤器。
Sub PC()
'code for WHS1
Worksheets("Multi_WHS_Pivot").Activate
ActiveSheet.PivotTables("Table").PivotFields("Branch").CurrentPage = "(All)"
With ActiveSheet.PivotTables("Table").PivotFields("Branch")
.ClearAllFilters
.EnableMultiplePageItems = True
.PivotItems("015") = True
.PivotItems("716") = True
.PivotItems("710") = True
End With
Worksheets("Main Data").Activate
End Sub
I am trying to adjust the filters of a pivot table based on predetermined settings.
I want to clear all the pivot table filters then select the filters.
The code gives me
Run-time error '1004': Unable to set the PivotItems property of the PivotField class.
It also doesn't clear the filter on the Pivot Table.
Sub PC()
'code for WHS1
Worksheets("Multi_WHS_Pivot").Activate
ActiveSheet.PivotTables("Table").PivotFields("Branch").CurrentPage = "(All)"
With ActiveSheet.PivotTables("Table").PivotFields("Branch")
.ClearAllFilters
.EnableMultiplePageItems = True
.PivotItems("015") = True
.PivotItems("716") = True
.PivotItems("710") = True
End With
Worksheets("Main Data").Activate
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尚未测试它,但是我修改了您的宏,以便它通过每个枢轴项目循环。对于每个枢轴项目,如果名称不等于“ 015”,“ 716”或“ 710”,则可见属性设置为false。
I haven't tested it, but I have amended your macro so that it loops through each pivot item. For each pivot item, if the name doesn't equal "015", "716", or "710", the visible property is set to False.