返回一个 PivotField 对象,该对象对应于选定的数据字段。
expression.DataField
expression 必需。该表达式返回一个 PivotCell 对象。
如果 PivotCell 对象不是下列允许的类型之一:XlPivotCellTypeValue、 XlPivotCellTypeDataField、 XlPivotCellTypeSubtotal 和 XlPivotCellTypeGrandTotal,那么该属性将返回一个错误。
本示例确定单元格 L10 是否在数据透视表的数据字段中,然后通过通知用户来返回对应于该单元格的数据透视表字段,或处理运行错误。本示例假定数据透视表位于活动的工作表上。
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