By Hemanta Sundaray on 2022-04-18
We can add fields to the data area of a pivot table using the AddFields method.
In the code block below, notice that we have two page fields: Customer Type & Brand. Whenever we have two or more fields in the AddFields method, we wrap these fields in an array function.
Sub Common_Pivot()
On Error Resume Next
ActiveSheet.PivotTables(1).AddFields _
RowFields:="Month", _
ColumnFields:="Division", _
PageFields:=Array("Customer Type", "Brand")
ActiveSheet.PivotTables(1).PivotFields("Sale Quantity").Orientation = xlDataField
End Sub
Note that you should never use the
DataFieldsargument in theAddFieldsmethod. Instead change the property of the field toxlDataField.
Executing the Sub procedure above gives us the following result: