VBA PivotField referencing drop down cell

Lindsay Flink 1 Reputation point

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:


0 comments No comments
{count} votes