PivotCell Members

Use the PivotCell object to get pivot table information from a Range object. Use the Range object’s PivotCell property to get a reference to this object. The PivotCell object has the following members:

Application

ColumnItems

Creator

CustomSubtotalFunction

DataField

Parent

PivotCellType

PivotField

PivotItem

PivotTable

Range

RowItems

Use PivotCell when working with user selections to find information about the selected cells. The following code displays pivot table information about the currently selected range:

Sub GetPivotCell(  )
    Dim pc As PivotCell
    On Error Resume Next
    ' Get the pivot cell
    Set pc = Selection.PivotCell
    Debug.Print pc.PivotCellType, _
      pc.PivotField.name, pc.PivotTable.name
    If Err Then Debug.Print "Selection is not in a pivot range."
    On Error GoTo 0
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.