Remarks

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:

Example

Use the PivotFields method of the PivotTable object to return the PivotFields collection. The following example enumerates the field names in the first PivotTable report on Sheet3.

Visual Basic for Applications
With Worksheets("sheet3").PivotTables(1) For i = 1 To .PivotFields.Count MsgBox .PivotFields(i).Name Next End With

Use (), where is the field name or index number, to return a single PivotFieldobject. The following example makes the Year field a row field in the first PivotTable report on Sheet3.

Visual Basic for Applications
Worksheets("sheet3").PivotTables(1) _ .PivotFields("year").Orientation = xlRowField
Pivot Fields Collection Object PivotFields Collection PivotFields Collection Object

See also:

index index