Pivot table - hide zero values

towners

Board Regular
Joined
Mar 12, 2009
Messages
225
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have several pivot charts and want to hide zero values.

The data is automatically collected from an external data source and I want to automate the pivot chart refresh etc.

Each pivot chart displays values from a number of columns of data, I only want to chart the data when any one of the columns has a value so I have included a simple "Sum" column that sums up the values of my data columns and have included this in my pivot table field list within the "Report Filter" section. Thus allowing me to deselect "0" values.

The problem is that when my data is refreshed any new values in the pivot table are not included because of the filter that is applied by deselecting "0". So currently I have to manually select all from the pivot table report filter and then deselect "0".

I want to perform this programatically so recorded the macro, here is the result.

Code:
    ActiveSheet.PivotTables("PivotTable4").PivotFields("Sum").CurrentPage = "(All)"
    With ActiveSheet.PivotTables("PivotTable4").PivotFields("Sum")
        .PivotItems("14").Visible = True
        .PivotItems("15").Visible = True
    End With
    ActiveSheet.PivotTables("PivotTable4").PivotFields("Sum"). _
        EnableMultiplePageItems = True
    ActiveSheet.PivotTables("PivotTable4").PivotFields("Sum").CurrentPage = "(All)"
    With ActiveSheet.PivotTables("PivotTable4").PivotFields("Sum")
        .PivotItems("0").Visible = False
    End With

My problem is the ".PivotItems" lines. Because the data is dynamic I can't know what new values need to be set to Visible and this is preventing me from programatically resetting the filter.

Can anyone help me with some code to refresh the pivot tables and reapply the filter to remove "0" values?

Thank you

Towners
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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
Back
Top