Unexpected behaviour from pivotfield.drilleddown property

Mightystomp

Board Regular
Joined
Jan 31, 2006
Messages
50
I am trying to make a macro that toggles expand/collapse pivotfield Profit Center

Code:
Sub ExpandCollapse()

Dim pt As PivotTable
Dim pf As PivotField


Set pt = ActiveSheet.PivotTables("PivotSAPBO")
Set pf = pt.PivotFields("[SAPBO].[Profit Center].[Profit Center]")


If pf.DrilledDown = False Then
    
    pf.DrilledDown = True

Else

    pf.DrilledDown = False
    
End If

End Sub

The problem is that pf.drilleddown returns false every time even if it has just been set to true. One can even put pf.drilleddown = true in line before and it still returns false.


I am using Excel 2013 and the pivottable is based on a table from Power Pivot.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I'm still trying to do the same as this in 2024 and amazingly can't find any answers :-(

It seems impossible to bring back the DrilledDown property into a variable.

You can create separate Macros to expand or collapse the PivotField.
But when you use an if statement, then it ALWAYS brings back "False" on the DrilledDown property.
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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