Simple(?) Pivot table VBA

df9864

Board Regular
Joined
Sep 28, 2004
Messages
108
I want to put some light code on a pivot table that expands / collapses detail.
The command to show / hide the detail works but I get an error on the IF statement:
"application or object defined error".
I suspect there's a problem with my syntax - any ideas?


If ActiveSheet.PivotTables("Mgr_Fcst_Plan_FTE1").PivotFields("Project Name").ShowDetail = False Then
ActiveSheet.PivotTables("Mgr_Fcst_Plan_FTE1").PivotFields("Project Name").ShowDetail = True
Else
ActiveSheet.PivotTables("Mgr_Fcst_Plan_FTE1").PivotFields("Project Name").ShowDetail = False
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Maybe your activesheet is not what you expect when you run the code? Then it's possible it can't find said pivottable, hence the error...

Try to replace ActiveSheet with the real sheet codename...
 
Upvote 0
The error is down to ActiveSheet.PivotTables("Mgr_Fcst_Plan_FTE1").PivotFields("Project Name").ShowDetail

You can set this to True/False but when checking the value VB returns

Code:
<Application-defined or object defined error>
 
Upvote 0
I don't know how to word it.

You can set .Showdetail to True or False

but you can't evaluate .Showdetail to find out currently if it True or False.

Trying to see if there is another way
 
Upvote 0
Could you have two command buttons?

One for:
Code:
ActiveSheet.PivotTables("Mgr_Fcst_Plan_FTE1").PivotFields("Project Name").ShowDetail = True

The other for:
Code:
ActiveSheet.PivotTables("Mgr_Fcst_Plan_FTE1").PivotFields("Project Name").ShowDetail = False
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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