代表樞紐分析表中的儲存格。
註解
使用 Range 集合的 PivotCell 屬性來傳回 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
方法
屬性
- Application
- CellChanged
- ColumnItems
- Creator
- CustomSubtotalFunction
- DataField
- DataSourceValue
- MDX
- Parent
- PivotCellType
- PivotColumnLine
- PivotField
- PivotItem
- PivotRowLine
- PivotTable
- Range
- RowItems
- ServerActions
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。