Filip Toma Isai
Filip Toma Isai

Reputation: 21

Expand/Collapse Specific Pivot Fields

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

Answers (1)

user2798634
user2798634

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

Related Questions