question

LindsayFlink-3227 avatar image
0 Votes"
LindsayFlink-3227 asked DSPatrick edited

VBA PivotField referencing drop down cell

I am trying to write VBA to adjust the row selection on a PivotTable. This is what I have so far

 Sub Addings_PivotFields()
 Dim pt As PivotTable
 Dim pf As PivotField
      
     Set pt = ActiveSheet.PivotTables("PivotTable2")
         For Each pf In pt.RowFields
         pf.Orientation = xlHidden
     Next pf
    
     Set pt = ActiveSheet.PivotTables("PivotTable2")
         pt.PivotFields("Category").Orientation = xlRowField
        
 End Sub

This works as is, but I'd like the pt.PivotFields("Category") to reference a cell that contains a list so I can toggle between it being grouped by Category and Account.

How do I get the last portion of code to reference cell D2 instead of typing in a column name?

Tables below for reference:
78869-capture.png


78834-capture2.png
78873-capture3.png


office-vba-dev
capture.png (10.5 KiB)
capture2.png (33.2 KiB)
capture3.png (25.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers