Resurrecting this thread - trying this again in 2024.
Why would the messagebox in this code give a FALSE???
The code successfully expands the pivottable field! So the field properly is definitely TRUE.
But trying to capture that property as a variable still yields FALSE....??
I even tried using "As Long" but unable to extract a TRUE or 1.
Sub Pivot_ExpandFields()
Dim PfName As String
Dim Pf As PivotField
Dim PfStatus As Boolean
PfName = ActiveCell.PivotField.Name
ActiveSheet.PivotTables(1).PivotFields(PfName).DrilledDown = True
MsgBox ActiveSheet.PivotTables(1).PivotFields(PfName).DrilledDown 'msgbox to display the current drilleddown property
this msgbox generates "FALSE" when it should be "TRUE"
End Sub
_________________________________________________________________________________________________________
Ideally, I want to create a toggle button like this (as opposed to the standard separate expand and collapse buttons):
Sub PivotField_Toggle()
Dim PfName As String
Dim Pf As PivotField
PfName = ActiveCell.PivotField.Name
If Not ActiveSheet.PivotTables(1).PivotFields(PfName).DrilledDown = False Then
ActiveSheet.PivotTables(1).PivotFields(PfName).DrilledDown = False
Else: ActiveSheet.PivotTables(1).PivotFields(PfName).DrilledDown = True
End If
End Sub
Any suggestions?
Bookmarks