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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
.PivotFields("FieldName").PivotItems("(blank)").Visible = False
 
Upvote 0
Sheets(sheetname).PivotTables(pivottablename).PivotFields(pivotfieldname).PivotItems("Grand Total").Visible = False
 
Upvote 0
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:
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,226
Members
448,878
Latest member
Da9l87

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