How to manipulate Pivot Fields in Pivot Table using VBA



     Webhosting by Godaddy     MS Excel Books
Home More Excel (VBA) Training Videos





Once you have created the Pivot table using the Pivot Cache to place the data in the memory, you can now start manipulating the Pivot Fields in the Pivot Tabel using VBA. The complete code with explanations is given below:
Manipulating PivotFields using VBA
Sub addFields()
With ActiveSheet.PivotTables(1)
'First row field
With .PivotFields("Name")
.Orientation = xlRowField
.Position = 1
End With

'Report Filter field
With .PivotFields("Location")
.Orientation = xlPageField
.Position = 1
End With

'Order Amount or numerical data  in the Values field
.AddDataField ActiveSheet.PivotTables(1).PivotFields("Order Amount"), _
"Sum of Amount", xlSum
End With
End Sub

Watch the Excel training video:



How to manipulate PivotFields in Pivot Table using VBA

Watch the video on YouTube

References
Using VBA to Manipulate PivotTable Reports

Home More Excel (VBA) Training Videos