PivotCell.DataField property (Excel)
Returns a PivotField object that corresponds to the selected data field.
Syntax
expression.DataField
expression A variable that represents a PivotCell object.
Remarks
This property returns an error if the PivotCell object is not one of the allowed constants of XlPivotCellType: xlPivotCellTypeDataField, xlPivotCellTypeSubtotal, or xlPivotCellTypeGrandTotal.
Example
This example determines if cell L10 is in the data field of the PivotTable, and either returns the PivotTable field that corresponds to the cell by notifying the user, or handles the run-time error. The example assumes that a PivotTable exists on the active worksheet.
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
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.