共用方式為


PivotTable.AddDataField Method (Excel)

Adds a data field to a PivotTable report. Returns a PivotField object that represents the new data field.

Syntax

expression .AddDataField(Field, Caption, Function)

expression A variable that represents a PivotTable object.

Parameters

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.

Return Value

PivotField

Example

This example adds a data field titled "Total Score" to a pivot table called "PivotTable1".

注意

This example assumes 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

請參閱

概念

PivotTable Object Members

PivotTable Object