Range![]() ![]() ![]() |
表示数据透视表中的一个单元格。
可用 Range 集合的 PivotCell 属性返回一个 PivotCell 对象。
返回一个 PivotCell 对象后,便可用 PivotCellType 属性来确定特定区域中的单元格类型。下例判断数据透视表中的单元格 A5 是否是数据项,并通知用户。本示例假定数据透视表位于活动工作表上,并且数据透视表包括单元格 A5。如果单元格 A5 不在数据透视表中,本示例将处理运行错误。
Sub CheckPivotCellType()
On Error GoTo Not_In_PivotTable
' Determine if cell A5 is a data item in the PivotTable.
If Application.Range("A5").PivotCell.PivotCellType = xlPivotCellValue Then
MsgBox "The PivotCell at A5 is a data item."
Else
MsgBox "The PivotCell at A5 is not a data item."
End If
Exit Sub
Not_In_PivotTable:
MsgBox "The chosen cell is not in a PivotTable."
End Sub
返回一个 PivotCell 对象后,便可用 ColumnItems 或 RowItems 属性来确定对应于列轴或行轴(代表选定编号)上的项目的 PivotItems 集合。下例用 PivotCell 对象的 ColumnItems 属性返回一个 PivotItemList 集合。
本示例确定单元格 B5 的数据项所在的列字段。然后判断列字段标题是否与“Inventory”相匹配,并通知用户。本示例假定数据透视表位于活动工作表上,并且工作表的 B 列包含数据透视表的列字段。
Sub CheckColumnItems()
' Determine if there is a match between the item and column field.
If Application.Range("B5").PivotCell.ColumnItems.Item(1) = "Inventory" Then
MsgBox "Item in B5 is a member of the 'Inventory' column field."
Else
MsgBox "Item in B5 is not a member of the 'Inventory' column field."
End If
End Sub