Pivot Table

JohnSeito

Active Member
Joined
Nov 19, 2007
Messages
390
How do I use VBA to unselect only the blank and 0 and have everything else selected.
I used to have this code and I forgot where it is and how to do that.

Thanks
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

par60056

Well-known Member
Joined
Jul 26, 2012
Messages
1,581
Office Version
  1. 2011
  2. 2010
Platform
  1. Windows
  2. MacOS
.PivotFields("FieldName").PivotItems("(blank)").Visible = False
 

CodeNinja

Well-known Member
Joined
Feb 18, 2013
Messages
634
Sheets(sheetname).PivotTables(pivottablename).PivotFields(pivotfieldname).PivotItems("Grand Total").Visible = False
 

JohnSeito

Active Member
Joined
Nov 19, 2007
Messages
390
Your code

.PivotFields("FieldName").PivotItems("(blank)").Visible = False

will not select blanks field in pivot table.

what I am trying to do is select everything, but not select blanks and 0.
How do I do that, I can put a code to say select this, this this, this, but it will not be good written code
because there are 30, 40, or 50 items and the code will be long and I sometimes don't know what items
there are since when the pivot table gets refresh there are new items.

I just know that I need to unselect Zeros and blanks but show everything else.

Thanks
 
Last edited:

par60056

Well-known Member
Joined
Jul 26, 2012
Messages
1,581
Office Version
  1. 2011
  2. 2010
Platform
  1. Windows
  2. MacOS
Hi John,
My code assumed that everything was visible and you just want to turn off the (blank) and 0 values.

Usually I build my pivot table and then hide the things so I rarely need to turn everything back on. But there are several ways.

You can try either of the following:

Code:
.PivotFields("FieldName").ClearManualFilter
.PivotFields("FieldName").PivotItems("0").Visible = False
.PivotFields("FieldName").PivotItems("(blank)").Visible = False

or

Code:
Dim pItem as PivotItem

For Each pItem in .PivotFields("FieldName").PivotItems
    If pItem.Name = "0" or pItem.Name="(blank)" then 
          pItem.visible = False
    Else
          pItem.visible = True
    End If
next
 

Watch MrExcel Video

Forum statistics

Threads
1,122,482
Messages
5,596,402
Members
414,063
Latest member
N_Bates

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