PivotFilters.Add method (Excel)

Adds new filters to the PivotFilters collection.

Syntax

expression.Add (Type, DataField, Value1, Value2, Order, Name, Description, MemberPropertyField, WholeDayFilter)

expression A variable that represents a PivotFilters object.

Parameters

Name Required/Optional Data type Description
Type Required XlPivotFilterType Requires an XlPivotFilterType type of filter.
DataField Optional Variant The field to which the filter is attached.
Value1 Optional Variant Filter value 1.
Value2 Optional Variant Filter value 2.
Order Optional Variant Order in which the data should be filtered.
Name Optional Variant Name of the filter.
Description Optional Variant A brief description of the filter.
MemberPropertyField Optional Variant Specifies the member property field on which the label filter is based.
WholeDayFilter Optional Variant Specifies a filter based on days.

Return value

PivotFilter

Example

Following are some examples of how to use the Add function correctly.

ActiveCell.PivotField.PivotFilters.Add FilterType := xlThisWeek 
 
ActiveCell.PivotField.PivotFilters.Add FilterType := xlTopCount DataField := MyPivotField2 Value1 := 10 
 
ActiveCell.PivotField.PivotFilters.Add FilterType := xlCaptionIsNotBetween Value1 := "A" Value2 := "G" 
 
ActiveCell.PivotField.PivotFilters.Add FilterType := xlValueIsGreaterThanOrEqualTo DataField := MyPivotField2 Value1 := 10000  

The following example returns a run-time error because the data type of Value1 is invalid.

ActiveCell.PivotField.PivotFilters.Add FilterType := xlValueIsGreaterThanOrEqualTo DataField := MyPivotField2 Value1 := Allan  

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.