using variables with the PivotItem class

match_pt

New Member
Joined
Dec 6, 2004
Messages
3
I'm getting an error that reads: Unable to set the visible property of the PivotItem class.

Can I use a variable to set the visible property? Maybe I'm just passing it in as the wrong type....

Here's the code:
Dim PivotWeek1 As String
PivotWeek1 = Sheets("Activity by Status").Range("C1").Value
With ActiveSheet.PivotTables("PivotTable4").PivotFields("Week")
.PivotItems(PivotWeek1).Visible = True
End With

Thanks!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
match_pt,
You can't set the visible property of an item to true if the field is custom sorted. If this is the case, set the pivot field autosort property to manual, set the item visible property to true and then reset the pivot field back to it's original setting.
Something like this.
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> test()
<SPAN style="color:#00007F">Dim</SPAN> PivotWeek1 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
PivotWeek1 = Sheets("Activity by Status").Range("C1").Value
<SPAN style="color:#00007F">With</SPAN> ActiveSheet.PivotTables("PivotTable4").PivotFields("Week")
    .AutoSort xlManual, .Name
    .PivotItems(PivotWeek1).Visible = <SPAN style="color:#00007F">True</SPAN>
    .AutoSort xlAscending, .Name <SPAN style="color:#007F00">'Adjust these settings to previous settings.</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,215,693
Messages
6,126,246
Members
449,304
Latest member
hagia_sofia

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