Excel) (PivotCell 对象

代表数据透视表中的一个单元格。

备注

使用 Range 集合的 PivotCell 属性返回 PivotCell 对象。

返回数据 透视单元格 对象后,可以使用 ColumnItems 或 RowItems 属性来确定与列或行轴上表示选定数字的项目对应的 PivotItems 集合。

示例

返回 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

此示例确定单元格 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

方法

属性

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。