Run Time error 1004; Unable to set the visible property of the pivot class item

pattersontod

New Member
Joined
Jan 17, 2017
Messages
2
I have a report that pulls in data from a database and updates existing pivot charts. The report has been running for a couple of years with not issues but recently started giving me the error "Run Time error 1004; Unable to set the visible property of the pivot class item" I am using 2007 Excel. Below is my code. The error stops on the line

"ActiveSheet.PivotTables("Top_Reasons_Per_Press").PivotFields("MONTH NUMBER").PivotItems(i).Visible = False"

Below is the code that updates one pivot chart. I don't understand why it quit working when it has worked for a couple of years without incident.
'This sectionrefreshes the Top Reasons per Press chart.

Sheets("Sheet12").Visible = True
<o:p> </o:p>Sheets("Sheet12").Select
<o:p>
</o:p>'Determine the parameters.
ValTotal3 = Sheets("ReferenceData").Range("A24").Value
ValEnd3 = ValTotal3 - 3
<o:p> </o:p>
ActiveSheet.PivotTables("Top_Reasons_Per_Press").PivotFields("MONTHNUMBER").ClearValueFilters

'Set all pivot itemsbefore the selected parameters to Visible=False.
WithSheets("Sheet12").PivotTables("Top_Reasons_Per_Press").PivotFields("MONTHNUMBER")

For i =1 To ValTotal3
ActiveSheet.PivotTables("Top_Reasons_Per_Press").PivotFields("MONTHNUMBER").PivotItems(i).Visible = True
Next i
For i = 1To ActiveSheet.PivotTables("Top_Reasons_Per_Press").PivotFields("MONTHNUMBER").PivotItems.Count - Month(Date)
ActiveSheet.PivotTables("Top_Reasons_Per_Press").PivotFields("MONTHNUMBER").PivotItems(i).Visible = False
Next i
ActiveSheet.PivotTables("Top_Reasons_Per_Press").PivotFields("MONTHNUMBER").PivotItems("(blank)").Visible = False
<o:p> </o:p>
End With
<o:p> </o:p>
Sheets("47K Charts").Select
<o:p> </o:p>
Sheets("Sheet12").Visible = False

 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,215,327
Messages
6,124,280
Members
449,149
Latest member
mwdbActuary

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