Excel) (PivotCell 物件

代表樞紐分析表中的儲存格。

註解

使用Range集合的PivotCell屬性可傳回PivotCell物件。

傳回 PivotCell 物件之後,您可以使用 ColumnItemsRowItems 屬性來判斷 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 支援與意見反應