AddFields Method

Applies To

PivotTable object.

Description

Adds row, column, and page fields to a PivotTable.

Syntax

expression.AddFields(RowFields, ColumnFields, PageFields, AddToTable)

expression Required. An expression that returns a PivotTable object.

RowFields Optional Variant. Specifies a pivot field name (or an array of pivot field names) to be added as rows.

ColumnFields Optional Variant. Specifies a pivot field name (or an array of pivot field names) to be added as columns.

PageFields Optional Variant. Specifies a pivot field name (or an array of pivot field names) to be added as pages.

AddToTable Optional Variant. True to add the fields to the PivotTable (none of the existing fields are replaced). False to replace existing fields with the new fields. The default value is False.

Remarks

You must specify one of the field arguments.

See Also

ColumnFields property, DataFields property, HiddenFields property, PageFields property, RowFields property, VisibleFields property.

Example

This example replaces the existing column fields in PivotTable one on Sheet1 with the Status and Closed_By fields.

Worksheets("Sheet1").PivotTables(1).AddFields _
    ColumnFields:=Array("Status", "Closed_By")