title | keywords | f1_keywords | ms.service | api_name | ms.assetid | ms.date | ms.localizationpriority | ||
---|---|---|---|---|---|---|---|---|---|
Application.SetAutoFilter method (Project) |
vbapj.chm2166 |
|
project-server |
|
4e4b4d4a-838b-f9b7-e3ab-d7bfa8efce5f |
06/08/2017 |
medium |
Sets the criteria for an AutoFilter for a specified field in a sheet view.
expression.SetAutoFilter (FieldName, FilterType, Test1, Criteria1, Operation, Test2, Criteria2)
expression An expression that returns an Application object.
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 comparison strings. |
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. |
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. |
Boolean
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.
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"
[!includeSupport and feedback]