What is the VBA equation for a “not equal to” auto filter?


You can use the <> symbol to represent “not equal to” within an AutoFilter in VBA.

Here is one common way to do so in practice:

Sub FilterNotEqualTo()

Range("A1:C11").AutoFilter Field:=2, Criteria1:="<>Center"

End Sub

This particular macro will filter all rows in the range A1:C11 where the value in the second column is not equal to “Center”.

The following example shows how to use this syntax in practice.

Example: Use “Not Equal to” in AutoFilter in VBA

Suppose we have the following dataset in Excel that contains information about various basketball players:

Suppose we would like to filter the dataset to only display the rows where the value in the Position column is not equal to “Center”.

We can create the following macro to do so:

Sub FilterNotEqualTo()

Range("A1:C11").AutoFilter Field:=2, Criteria1:="<>Center"

End Sub

When we run this macro, we receive the following output:

Notice that the dataset has been filtered to only show the rows where the value in the Position column is not equal to “Center”.

Note that you could also filter the rows where the value in the Position column is not equal to multiple values.

For example, you could create the following macro to filter the dataset to only show rows where the value in the Position column is not equal to “Center” and not equal to “Guard”:

Sub FilterNotEqualTo()

Range("A1:C11").AutoFilter Field:=2, Criteria1:="<>Center", Criteria2:="<>Guard"

End Sub

Noticed that the dataset has been filtered to only show rows where the value in the Position column is not equal to “Center” and not equal to “Guard”:

Note: You can find the complete documentation for the VBA AutoFilter method .

VBA: How to Use AutoFilter with Multiple Criteria

x