PivotTable.AddFields method (Excel)
Adds row, column, and page fields to a PivotTable report or PivotChart report.
Syntax
expression.AddFields (RowFields, ColumnFields, PageFields, AddToTable)
expression A variable that represents a PivotTable object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
RowFields | Optional | Variant | Specifies a field name (or an array of field names) to be added as rows or added to the category axis. |
ColumnFields | Optional | Variant | Specifies a field name (or an array of field names) to be added as columns or added to the series axis. |
PageFields | Optional | Variant | Specifies a field name (or an array of field names) to be added as pages or added to the page area. |
AddToTable | Optional | Variant | Applies only to PivotTable reports. True to add the specified fields to the report (none of the existing fields are replaced). False to replace existing fields with the new fields. The default value is False. |
Return value
Variant
Remarks
You must specify one of the field arguments.
Field names specify the unique name returned by the SourceName property of the PivotField object.
This method is not available for OLAP data sources.
Example
This example replaces the existing column fields in the first PivotTable report on Sheet1 with the Status and Closed_By fields.
Worksheets("Sheet1").PivotTables(1).AddFields _
ColumnFields:=Array("Status", "Closed_By")
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.