Developer technologies | Visual Basic for Applications
An implementation of Visual Basic that is built into Microsoft products.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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: