PivotFields Collection Object
Description
A collection of all the PivotField objects in a PivotTable.
Using the PivotFields Collection
Use the PivotFields method to return the PivotFields collection. The following example enumerates the pivot field names in PivotTable one on Sheet3.
With Worksheets("Sheet3").PivotTables(1)
For i = 1 To .PivotFields.Count
MsgBox .PivotFields(i).Name
Next
End With
Use PivotFields(index), where index is the pivot-field name or index number, to return a single PivotField object. The following example makes the Year field a row field in PivotTable one on Sheet3.
Worksheets("Sheet3").PivotTables(1) _
.PivotFields("Year").Orientation = xlRowField
In some cases, it may be easier to use one of the properties that returns a subset of the PivotTable fields. The following accessor methods are available:
- ColumnFields property
- DataFields property
- HiddenFields property
- PageFields property
- RowFields property
- VisibleFields property
Properties
Application property, Count property, Creator property, Parent property.
Methods
Item method (PivotFields collection).