FilterOn Property

Microsoft Office Web Components Visual Basic

expression.FilterOn

expression    Required. An expression that returns a PivotField object.

Example

This example applies a conditional filter to the Store City field based on the Profit total. The three most profitable stores are displayed.

Sub TopThreeStores()

    Dim ptView
    Dim ptConstants
    Dim fldFilterField

    Set ptConstants = PivotTable1.Constants

    ' Set a variable to the active view of the PivotTable list.
    Set ptView = PivotTable1.ActiveView

    ' Set a variable to the field that is to be filtered.
    Set fldFilterField = PivotTable1.ActiveData.RowAxis.Fields("Store City")

    ' Filter the stores based on profit.
    Set fldFilterField.FilterOn = ptView.Totals("Profit")

    ' Set the function used to filter the stores.
    fldFilterField.FilterFunction = ptConstants.plFilterFunctionTopCount

    ' Display the three most profitable stores.
    fldFilterField.FilterFunctionValue = 3

End Sub