Skip to content

Instantly share code, notes, and snippets.

@ateneva
Last active April 21, 2018 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ateneva/7b8759421a8e93e3dd75b0d702eaf513 to your computer and use it in GitHub Desktop.
Save ateneva/7b8759421a8e93e3dd75b0d702eaf513 to your computer and use it in GitHub Desktop.
How do I quickly re-arrange Pivot Table Layout in VBA?
Sub ShowFieldinPT()
Dim Wks As Worksheet
Dim PT As PivotTable
Dim PF As PivotField
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'written by Angelina Teneva, Sept 2016
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For Each Wks In ActiveWorkbook.Worksheets
For Each PT In Wks.PivotTables
For Each PF In PT.PivotFields
Set PF = PT.PivotFields("Country")
If PF.Orientation <> xlHidden Then
'comment out as needed
PF.Orientation = xlPageField 'as ReportFilter
PF.Orientation = xlRowField 'as RowField
PF.Orientation = xlColumnField 'as ColumnField
PF.Orientation = xlDataField 'as Value Field
End If
Next PF
Next PT
Next Wks
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment