CalculatedFields 方法 (Excel)CalculatedFields.Add method (Excel)

创建新的计算字段。Creates a new calculated field. 返回一个**透视字段** 对象。Returns a PivotField object.


表达式(NameFormulaUseStandardFormula)expression.Add (Name, Formula, UseStandardFormula)

_表达式_一个代表**CalculatedFields** 对象的变量。expression A variable that represents a CalculatedFields object.


名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
NameName 必需Required StringString 域名。The name of the field.
FormulaFormula 必需Required StringString 字段的公式。The formula for the field.
UseStandardFormulaUseStandardFormula 可选Optional VariantVariant 为实现向上兼容,该值默认为 FalseFalse (default) for upward compatibility. 对于包含在字段名称的任何参数中的字符串, 为True ;将被解释为采用标准的美国英语格式, 而不是本地设置。True for strings contained in any arguments that are field names; will be interpreted as having been formatted in standard U.S. English instead of local settings.

返回值Return value

一个代表新计算字段的 PivotFieldA PivotField that represents the new calculated field.


此示例向第一张工作表上的第一张数据透视表添加计算字段。This example adds a calculated field to the first PivotTable report on worksheet one.

Worksheets(1).PivotTables(1).CalculatedFields.Add "PxS", _ 
 "= Product * Sales"

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.