VBA for Pivot Table -- Select All, then deselect values = 0

bisel

Board Regular
Joined
Jan 4, 2010
Messages
152
Am trying to create a macro using VBA that will select a pivot table's primary filter (Years Total) and select All. Then once selected, de-select the values = 0. I tried to do this by recording a macro but i get the following code when I record the macro ...

VBA Code:
Sub pivottable_refresh()
    
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Years Total").CurrentPage = "(All)"

End Sub

... which does not work.

Why I want this? Because in my workbook, data can change by adding additional data elements. Unless I manually refresh the pivot table, it is likely that it will not reflect the current data.

Appreciate any help.

Regards,

Steve
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
11,033
Office Version
  1. 2019
Platform
  1. Windows
This is what I get from the macro recorder by following the same steps that you describe.
VBA Code:
Sub pivottable_refresh()
    
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Years Total").PivotItems("0").Visible = False

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,114,443
Messages
5,547,955
Members
410,820
Latest member
Prepost
Top