title | keywords | f1_keywords | api_name | ms.assetid | ms.date | ms.localizationpriority | ||
---|---|---|---|---|---|---|---|---|
PivotTable.AddDataField method (Excel) |
vbaxl10.chm235142 |
|
|
768b1eb7-80ea-fb0f-0de5-803ec19bbe18 |
05/08/2019 |
medium |
Adds a data field to a PivotTable report. Returns a PivotField object that represents the new data field.
expression.AddDataField (Field, Caption, Function)
expression A variable that represents a PivotTable object.
Name | Required/Optional | Data type | Description |
---|---|---|---|
Field | Required | Object | The unique field on the server. If the source data is Online Analytical Processing (OLAP), the unique field is a cube field. If the source data is non-OLAP (non-OLAP source data), the unique field is a PivotTable field. |
Caption | Optional | Variant | The label used in the PivotTable report to identify this data field. |
Function | Optional | Variant | The function performed in the added data field. |
PivotField
This example adds a data field titled Total Score to a PivotTable called PivotTable1. This example assumes that a table exists in which one of the columns contains a column titled Score.
Sub AddMoreFields()
With ActiveSheet.PivotTables("PivotTable1")
.AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Score"), "Total Score"
End With
End Sub
[!includeSupport and feedback]