Class PivotItems (Excel VBA)

A collection of all the PivotItem objects in a PivotTable field. To use a PivotItems class variable it first needs to be instantiated, for example


Dim pis as PivotItems
Set pis = ActiveCell.PivotField.PivotItems()

Add

Creates a new PivotTable item.

Add (Name)

Name: The name of the new PivotTable item.


Worksheets(1).PivotTables(1).PivotItems("Year").Add "1998"

Count

Returns a Long value that represents the number of objects in the collection.


Dim lngCount As Long
lngCount = ActiveCell.PivotField.PivotItems.Count

Item

Returns a single object from a collection.

The text name of the object is the value of the Name and Value properties.

Item (Index)

Index: The name or index number for the object.


Dim pvti As PivotItem
Set pvti = ActiveCell.PivotField.PivotItems(Index:=1)