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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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,221,899
Messages
6,162,682
Members
451,782
Latest member
LizN

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