Class PivotCell (Excel VBA)

The class PivotCell represents a cell in a PivotTable report.

Set

To use a PivotCell class variable it first needs to be instantiated, for example

Dim lngIndex As Long: lngIndex = 
Dim pvtln As PivotLine: Set pvtln = 
Dim pvtlcelPivotLineCell As PivotCell
Set pvtlcelPivotLineCell = pvtln.PivotLineCells(Index:=lngIndex)

The following procedures can be used to set variables of type PivotCell: PivotLineCells.Item, PivotValueCell.PivotCell, Range.PivotCell, ValueChange.PivotCell, PivotLine.PivotLineCells and PivotLine.PivotLineCellsFull

For Each

Here is an example of processing the PivotCell items in a collection.

Dim pvtln As PivotLine: Set pvtln = 
Dim pvtlcelPivotLineCell As PivotCell
For Each pvtlcelPivotLineCell In pvtln.PivotLineCells
	
Next pvtlcelPivotLineCell

Themes

Some procedures in this class have been grouped together in themes and are described on separate theme pages

Cell with its procedures CellChanged and PivotCellType
Column with its procedures ColumnItems and PivotColumnLine
Row with its procedures PivotRowLine and RowItems

Properties

CustomSubtotalFunction returns the custom subtotal function field setting of a PivotCell object.

Sub UseCustomSubtotalFunction() 
 
 On Error GoTo Not_A_Function 
 
 ' Determine if custom subtotal function is a count function. 
 If Application.Range("C20").PivotCell.CustomSubtotalFunction = xlCount Then 
 MsgBox "The custom subtotal function is a Count." 
 Else 
 MsgBox "The custom subtotal function is not a Count." 
 End If 
 Exit Sub 
 
Not_A_Function: 
 MsgBox "The selected cell is not a custom subtotal function." 
 
End Sub

DataField returns a PivotField object that corresponds to the selected data field.

Sub CheckDataField() 
 
 On Error GoTo Not_In_DataField 
 
 MsgBox Application.Range("L10").PivotCell.DataField 
 Exit Sub 
 
Not_In_DataField: 
 MsgBox "The selected range is not in the data field of the PivotTable." 
 
End Sub

DataSourceValue returns the value last retrieved from the data source for edited cells in a PivotTable report.

MDX returns a tuple that provides the full MDX coordinates of the specified value cell in a PivotTable with an OLAP data source.

Parent returns the parent object for the specified object. Read-only.

PivotField returns a PivotField object that represents the PivotTable field containing the upper-left corner of the specified range.

Worksheets("Sheet1").Activate 
MsgBox "The active cell is in the field " & _ 
 ActiveCell.PivotField.Name

PivotItem returns a PivotItem object that represents the PivotTable item containing the upper-left corner of the specified range.

Worksheets("Sheet1").Activate 
MsgBox "The active cell is in the item " & _ 
 ActiveCell.PivotItem.Name

PivotTable returns a PivotTable object that represents the PivotTable report associated with the PivotCell.

Set pvtTable = Worksheets("Sheet1").Range("A3").PivotTable 
pvtTable.PivotFields("Country").CurrentPage = "Canada"

Range returns a Range object that represents the range that the specified PivotCell applies to.

rAddress = Worksheets("Crew").AutoFilter.Range.Address

ServerActions represents a collection of actions consisting of OLAP-defined actions that can be executed. The actions are specific to PivotTables existing at a worksheet-level.

ActiveSheet.ChartObjects("Chart 1").Chart.PivotLayout.PivotTable.PivotColumnAxis.PivotLines(index of line ).PivotLineCells(index of cells ).ServerAction("OLAP Action name" ).Execute

PivotLineCells.Count returns the number of items in the PivotLineCells collection.

PivotLineCells.Full when True, all of the PivotLineCells in the PivotLine (including those that are hidden in compact form) are retrieved.

PivotLineCells.Item returns a specific element of the PivotLineCells collection object by its position in the collection.

PivotLineCells.Parent returns the parent object for the specified PivotLineCells object. Read-only.