VBA Pivot Table - Pivot Items to show in Pivot Table

Jeep56

Board Regular
Joined
Mar 21, 2013
Messages
57
Hi,
I've written the following code for my pivot table. The Pivot Items. visible= "false" I do not want showing on my report. I only want the 4 items that equal True. Everything was working but this month, one of the Asset Types "B412D"
was not in my data so it crashed on line .PivotItems("B412D").Visible = False

Is there a better way to write this code to avoid it crashing when it does not find the Asset Type in the data being used? I have little VBA experience.

'Adds Asset Type to show on Pivot Table
.PivotFields("Asset Type").Orientation = xlRowField

With ActiveSheet.PivotTables("FlyingDays").PivotFields("Asset Type")
.PivotItems("B206").Visible = True
.PivotItems("B412").Visible = True
.PivotItems("C90B").Visible = True
.PivotItems("B206C").Visible = False
.PivotItems("B412C").Visible = False
.PivotItems("B412D").Visible = False
.PivotItems("B412S").Visible = False
.PivotItems("C90BI").Visible = False
.PivotItems("C90BS").Visible = False
.PivotItems("G120A").Visible = True
.PivotItems("GCPT4").Visible = False
.PivotItems("GCPT5").Visible = False
.PivotItems("G-DTT").Visible = False
.PivotItems("Room").Visible = False
.PivotItems("(blank)").Visible = False
End With

Thanks in advance for the help
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,195,671
Messages
6,011,075
Members
441,581
Latest member
rp4717

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