macro error

mcmdm50

New Member
Joined
Mar 25, 2012
Messages
14
Using Excel 2016, I have a macro that works well if the data is in the pivot table, but if not, it throws an error (Run-Time error '1004': Unable to get the PivotItems proery of the PivotField class).
It is try to deselect the District Bank and Regional Trust but they may or may not not appear when macro runs.
Is there a way to prevent the macro from hanging up here?
Thanks,

ActiveSheet.PivotTables("PivotTable1").PivotFields("Branch").CurrentPage = _
"(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Branch")
.PivotItems("District Bank - Direct").Visible = False
.PivotItems("District Bank - Retail").Visible = False
.PivotItems("Regional Trust - North 1").Visible = False
.PivotItems("Regional Trust - South 1").Visible = False
.PivotItems("(blank)").Visible = False
End With
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You can make a loop through all the items and control of the name is the same as you wish.
 
Upvote 0
I don't know how to do what you recommend but would love to learn if you can direct me to reference.
However, I was given a suggestion from a friend (below) that solved the problem....
The easiest way is to insert a line
On Error Resume Next<o:p></o:p>
above the lines With ....<o:p></o:p>

You may want to insert<o:p></o:p>

On Error GoTo 0<o:p></o:p>

below End With, to restore normal error handling.

But thank you very much for your response.
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,846
Members
449,194
Latest member
HellScout

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