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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

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
644
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
 
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,424
Messages
5,837,155
Members
430,479
Latest member
mamush200

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