Application.SetAutoFilter Method (Project)
Sets the criteria for an AutoFilter for a specified field in a sheet view.
Version Information
Version Added: Project 2010
Syntax
expression .SetAutoFilter(FieldName, FilterType, Test1, Criteria1, Operation, Test2, Criteria2)
expression An expression that returns an Application object.
Parameters
Name |
Required/Optional |
Data Type |
Description |
---|---|---|---|
FieldName |
Required |
String |
Name of the field. |
FilterType |
Optional |
PjAutoFilterType |
Type of filter; can be one of the PjAutoFilterType constants. The default value is pjAutoFilterClear, which clears the AutoFilter. |
Test1 |
Optional |
String |
Specifies the type of comparison for the first test. Requires that FilterType is pjAutoFilterCustom, and that Criteria1 specifies a value. Can be one of the following comparison strings:
Comparison String Description
"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.
|
Criteria1 |
Optional |
String |
The value of the first comparison with the value of the field specified by FieldName. |
Operation |
Optional |
String |
The logical operation if there is a second test. The Operation value can be "And" or "Or". |
Test2 |
Optional |
String |
Specifies 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. |
Criteria2 |
Optional |
String |
The value of the second comparison with the value of the field specified by FieldName. |
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"