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

bisel

Board Regular
Joined
Jan 4, 2010
Messages
195
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
14,761
Office Version
  1. 365
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,120
Messages
5,835,504
Members
430,362
Latest member
ConnerJ

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top