Expression Property

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Returns or sets a String that represents the expression used to calculate the specified calculated field or calculated total. The expression must be compatible with the Jet expression service. Read/write.

expression.Expression

expression   Required. An expression that returns a one of the objects in the Applies To list.

Remarks

The Expression property will return a blank string if it is not used with a calculated field or calculated total.

Example

The following example displays the current expression used for a calculated field named "Variance" in PivotTable1. When you edit the expression and then click OK, the new expression is assigned to the Variance field.

  Sub Change_Expression()

    Dim vwView
    Dim cfCalcField
    Dim strCurrentExpression
    Dim strNewExpression

    Set vwView = PivotTable1.ActiveView

    ' Set a varible to the calculated field.
    Set cfCalcField = _
        vwView.Fieldsets("Variance").Fields("Variance")

    ' Set a variable to the current expression used in the
    ' Variance field.
    strCurrentExpression = cfCalcField.Expression

    ' Display an input box that contains the current expression for the
    ' Variance field. Edit the expression and then click OK.
    strNewExpression = InputBox("Edit the expression used for the calculated" & _
        "field and then click OK.", , strCurrentExpression)

    ' Set the expression used to calculate the Variance field to the
    ' expression entered in the input box.
    cfCalcField.Expression  = strNewExpression

End Sub