I have 16 pivot tables on the same sheet, "Analytics Admin", I recorded and cleaned up the macro below (the code right before updates the info the pivot tables source). It's basically the same code 16 times, the only thing that changes is the pivot table name ( MSP, MSP30, FSP, FSP30, etc). Is it possible to change the report filter for all the pivot tables at once?
Worksheets("Analytics Admin").Activate
'refreshes all data, clears all filters then filters 0 and blanks out of all custom range pareto pivot tables
ActiveSheet.PivotTables("MSP").PivotCache.Refresh
ActiveSheet.PivotTables("MSP").PivotFields("count").ClearAllFilters
ActiveSheet.PivotTables("MSP").PivotFields("count").ShowAllItems = True
With ActiveSheet.PivotTables("MSP").PivotFields("count")
.PivotItems("0").Visible = False
.PivotItems("(blank)").Visible = False
End With
ActiveSheet.PivotTables("MSP").PivotCache.Refresh
ActiveSheet.PivotTables("FSP").PivotCache.Refresh
ActiveSheet.PivotTables("FSP").PivotFields("count").ClearAllFilters
ActiveSheet.PivotTables("FSP").PivotFields("count").ShowAllItems = True
With ActiveSheet.PivotTables("FSP").PivotFields("count")
.PivotItems("0").Visible = False
.PivotItems("(blank)").Visible = False
End With
ActiveSheet.PivotTables("FSP").PivotCache.Refresh
Something along the lines of (not tested, just typed into here)
dim ws as Worksheet
set ws = ThisWorkbook.Worksheets("Analytics Admin")
dim pt as PivotTable
For Each pt In ws.PivotTables
' Debug.Print Pivot.Name
pt.PivotFields("count").ClearAllFilters
pt.PivotFields("count").ShowAllItems = True
With pt.PivotFields("count")
.PivotItems("0").Visible = False
.PivotItems("(blank)").Visible = False
End With
pt.PivotCache.Refresh
pt.refreshTable
pt.Update
Next
If you have Excel 2010 or later, and most (hopefully all) of these Pivots share the exact same data source, you can do this with little or no looping. Simply set up a Slicer on the "count" field and then connect it to all the PivotTables (right click on the Slicer, and select "Report Connections". Then you only need to run the code on one of those PivotTables, and all the others will update automatically.
You can hide the Slicer somewhere if you don't want users to click it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.