Application.FilterEdit method (Project)

Creates, edits, or copies a filter.

Syntax

expression.FilterEdit (Name, TaskFilter, Create, OverwriteExisting, Parenthesis, NewName, FieldName, NewFieldName, Test, Value, Operation, ShowInMenu, ShowSummaryTasks)

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data type Description
Name Required String The name of a filter to edit, create, or copy.
TaskFilter Required Boolean True if the filter specified with Name contains task information. False if the filter contains resource information.
Create Optional Boolean True if a new filter is created. The new filter is a copy of the filter specified with Name and is given the name specified with NewName. If NewName is empty, the new filter is given the name specified by Name. The default value is False.
OverwriteExisting Optional Boolean True if the existing filter is overwritten with a new filter. The default value is False.
Parenthesis Optional Boolean True if the criterion established by FieldName, Test, and Value is evaluated as a parenthetical AND or OR clause (the value specified with Operation) in relation to other criteria, in the manner of (a AND b) OR c.
NewName Optional String A new name for the filter specified with Name (Create is False) or a name for the new filter (Create is True). If NewName is empty and Create is False, the filter specified with Name retains its current name. The default value is Empty.
FieldName Optional String The name of a field to change.
NewFieldName Optional String A new name for the field specified with FieldName.
Test Required String The type of comparison made between FieldName and Value that acts as selection criteria for the filter. Can be one of the comparison strings.
Value Optional String The value to compare with the value of the field specified with FieldName.
Operation Optional String How the criterion established with FieldName, Test, and Value relates to other criteria in the filter. The Operation argument can be set to "And" or "Or".
ShowInMenu Optional Boolean True if the filter is displayed in the Filter drop-down list. The default value is False. Note To display the list of filters, on the Ribbon, on the View tab, click the Filter drop-down list.
ShowSummaryTasks Optional Boolean True if the summary tasks of the filtered tasks are displayed. The default value is False.

Comparison strings

Comparison string Description
"equals" The value of FieldName equals Value.
"does not equal" The value of FieldName does not equal Value.
"is greater than" The value of FieldName is greater than Value.
"is greater than or equal to" The value of FieldName is greater than or equal to Value.
"is less than" The value of FieldName is less than Value.
"is less than or equal to" The value of FieldName is less than or equal to Value.
"is within" The value of FieldName is within Value.
"is not within" The value of FieldName is not within Value.
"contains" FieldName contains Value.
"does not contain" FieldName does not contain Value.
"contains exactly" FieldName exactly contains Value.

Return value

Boolean

Example

The following example creates a filter (if one does not exist) for tasks with the highest priority, and then applies the filter.

Sub CreateAndApplyHighestPriorityFilter() 
    Dim TaskFilter As Variant  ' Index for For Each loop. 
    Dim Found As Boolean    ' Whether or not the filter exists. 
    Found = False   ' Assume the filter does not exist. 
    ' Look for filter. 
    For Each TaskFilter In ActiveProject.TaskFilterList 
        If TaskFilter = "Highest Priority" Then 
            Found = True 
            Exit For 
        End If 
    Next TaskFilter 
 
    ' If filter doesn't exist, create it. 
    If Not Found Then FilterEdit Name:="Highest Priority", _ 
        Create:=True, TaskFilter:=True, FieldName:="Priority", _ 
        Test:="equals", Value:="Highest" 
    FilterApply "Highest Priority" 
End Sub    

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.