PivotItems 集合对象

         
PivotTables (PivotTable)
Pivot
PivotItems (PivotItem)

数据透视表字段中所有 PivotItem 对象的集合。这些对象为字段分类中的独立数据项。

PivotItems 集合对象的用法

可用 PivotItems 方法返回 PivotItems 集合。下例为工作表“Sheet4”上第一张数据透视表中所有的字段名和字段中的数据项名创建一个列表。

Worksheets("sheet4").Activate
With Worksheets("sheet3").PivotTables(1)
    c = 1
    For i = 1 To .PivotFields.Count
        r = 1
        Cells(r, c) = .PivotFields(i).Name
        r = r + 1
        For x = 1 To .PivotFields(i).PivotItems.Count
            Cells(r, c) = .PivotFields(i).PivotItems(x).Name
            r = r + 1
        Next
        c = c + 1
    Next
End With

可用 PivotItems(index) 返回单个 PivotItem 对象,其中 index 为数据透视表项目编号或名称。下例将隐藏工作表“Sheet3”上第一张数据透视表中字段“Year”中包含的所有“1998”的数据项。

Worksheets("sheet3").PivotTables(1) _
    .PivotFields("year").PivotItems("1998").Visible = False