1

I have a line of VBA code that creates a filter with one condition, this works well:

FilterEdit Name:="temp", TaskFilter:=True, Create:=True, OverwriteExisting:=True, FieldName:="Resource Names", Test:="contains", Value:='Electician', ShowInMenu:=False, ShowSummaryTasks:=False

The equivalent popup window would be:

Filter Definition Popup for One Condition

1

However I want to filter for rows containing that string AND have an outline level greater than 2.

The filter popup for this is:

Filter Definition Popup for Two Conditions

2

The filter popup would work well if I only needed it once, however the conditions I use change dynamically so I need to define it using VBA.

The Microsoft Documentation for FilterEdit mentions the Operation argument but there is no example of how to use it.

I tried stringing together several arguments in the function but it did not work:

FilterEdit Name:="temp", TaskFilter:=True, Create:=True, OverwriteExisting:=True, FieldName:="Resource Names", Test:="contains", Value:='Electician', Operation:="And", FieldName:="Outline Level", Test:="is less than or equal to", Value:=2, ShowInMenu:=False, ShowSummaryTasks:=False

1 Answer 1

0

Creating multiple criteria in a filter requires additional calls to the FilterEdit method as such:

Sub MakeFilter()
    
    FilterEdit Name:="temp", TaskFilter:=True, Create:=True, OverwriteExisting:=True _
        , FieldName:="Resource Names", Test:="contains", Value:="Electrician" _
        , ShowInMenu:=False, ShowSummaryTasks:=False
        
    FilterEdit Name:="temp", TaskFilter:=True, FieldName:="", NewFieldName:="Outline Level" _
        , Test:="is less than or equal to", Value:="2", Operation:="And"

End Sub

Note that Value is always a string and that optional arguments do not always need to be included if the default value is desired (see documentation in link above).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much, this worked great. Future readers: make note of needing to use FieldName:="", NewFieldName:== in the second criteria row.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.