VBA help with pivot tables in excel

nancymk

Board Regular
Joined
Jul 24, 2008
Messages
106
For a certain field in my pivot table (lets call it field1) I want to show only choices 1-5 and remove blanks and anything else that pops up. The problem is, there are a lot of other things that could be in field1, so it's not has easy as turning off the visibility for blanks. Also, there might not be 1-5 every time.

How would I change this code to turn visibility for all other choices to false and not crash if say there is no 2.

Sheets("Com").Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Field1")
.PivotItems("1").Visible = True
.PivotItems("2").Visible = True
.PivotItems("3").Visible = True
.PivotItems("4").Visible = True
.PivotItems("5").Visible = True
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
just an fyi - this is going with whole bunch of other code in a process, so not creating a macro for just this simple task :)
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,845
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