Share via


PivotFields Collection Object

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.


Aa218954.parchild(en-us,office.10).gifPivotFields
Aa218954.space(en-us,office.10).gifAa218954.parchild(en-us,office.10).gifPivotField

A collection of all the PivotField objects in a PivotTable report.

Using the PivotFields Collection

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.

  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 field name or index number, to return a single PivotField object. The following example makes the Year field a row field in the first PivotTable report 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: