Table of contents
TOC
Collapse the table of content
Expand the table of content

Application.SetAutoFilter Method (Project)

office 365 dev account|Last Updated: 10/19/2017
|
2 Contributors

Sets the criteria for an AutoFilter for a specified field in a sheet view.

Syntax

expression. SetAutoFilter (FieldName, FilterType, Test1, Criteria1, Operation, Test2, Criteria2)

expression An expression that returns an Application object.

Parameters

NameRequired/OptionalData TypeDescription
FieldNameRequiredStringName of the field.
FilterTypeOptionalPjAutoFilterTypeType of filter; can be one of the PjAutoFilterType constants. The default value is pjAutoFilterClear, which clears the AutoFilter.
Test1OptionalStringSpecifies the type of comparison for the first test. Requires that FilterType is pjAutoFilterCustom, and that Criteria1 specifies a value. Can be one of the comparison strings.
Criteria1OptionalStringThe value of the first comparison with the value of the field specified by FieldName.
OperationOptionalStringThe logical operation if there is a second test. The Operation value can be "And" or "Or".
Test2OptionalStringSpecifies the type of comparison for the second test. Requires that FilterType is pjAutoFilterCustom, the Operation value must be set, and that Criteria2 specifies a value. The string can be one of the comparisons in the table for Test1.
Criteria2OptionalStringThe value of the second comparison with the value of the field specified by FieldName.


Comparison strings

Comparison stringDescription
"equals"The value of FieldName equals Criteria1.
"does not equal"The value of FieldName does not equal Criteria1.
"is greater than"The value of FieldName is greater than Criteria1.
"is greater than or equal to"The value of FieldName is greater than or equal to Criteria1.
"is less than"The value of FieldName is less than Criteria1.
"is less than or equal to"The value of FieldName is less than or equal to Criteria1.
"is within"The value of FieldName is within Criteria1.
"is not within"The value of FieldName is not within Criteria1.


Return value

Boolean

Remarks

To turn the AutoFilter feature on or off, see the AutoFilter method.

Note

A column name in a sheet view can have a different title than the name of the field it shows.

Example

The following example sets a custom AutoFilter for the "% Work Complete" field.

Sub TestAutoFilter() 
    If Not ActiveProject.AutoFilter Then 
        Application.AutoFilter 
    End If 

    Application.SetAutoFilter FieldName:="% Work Complete", FilterType:=pjAutoFilterCustom, _ 
    Test1:="equals", Criteria1:="0%" 
End Sub

If there is an AutoFilter set for the "% Work Complete" field, the following line of code clears the AutoFilter because the default value for the optional FilterType argument is pjAutoFilterClear.

Application.SetAutoFilter FieldName:="% Work Complete"
© 2018 Microsoft