Reputation: 21
I need a button that at any click will collapse/expand a certain field in a pivot table.
I have the code for expand and collapse separately.
'At click collapse field
Range("B5:B8").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("MD").ShowDetail = False
'At another click collapse
Range("B5:B8").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("MD").ShowDetail = True
Upvotes: 1
Views: 1607
Reputation: 13
I think this is what your looking for
Set pf = pt.PivotFields(r.PivotField.Name)
pf.ShowDetail = IIf(r.ShowDetail, False, True)
Upvotes: 1