J.Khoo
J.Khoo

Reputation: 33

Autofilter with 3 criterias

I have tried to use vba to autofilter 3 criteria but it isn't reading the both values given. Below is the code im using it just reads "MY18" and not "MY 18"

Sub Macro2()
'
' Macro2 Macro
'

'
    Selection.AutoFilter
    ActiveWindow.SmallScroll ToRight:=7
    ActiveSheet.Range("$A$1:$M$138").AutoFilter Field:=9, Criteria1:="FY17"
    ActiveSheet.Range("$A$1:$M$138").AutoFilter Field:=2, Criteria1:=Array("=*MY 18*", "=*MY18*") _
        , Operator:=xlAnd, Criteria2:="<>*discussion*"



End Sub

Upvotes: 0

Views: 6863

Answers (2)

Graciela
Graciela

Reputation: 1

It worked for me using the code below:

ActiveSheet.Range("A1:AJ50").AutoFilter Field:=7, Criteria1:=Array("ABC", "DEF", "GHI"), Operator:=xlFilterValues

I know it is too late but it may be useful for someone else.

Upvotes: 0

Mrig
Mrig

Reputation: 11702

In the below line

ActiveSheet.Range("$A$1:$M$138").AutoFilter Field:=2, Criteria1:=Array("=*MY 18*", "=*MY18*") _
    , Operator:=xlAnd, Criteria2:="<>*discussion*"

Replace, Operator:=xlAnd with Operator:=xlFilterValues

EDIT :

ActiveSheet.Range("$A$1:$M$138").AutoFilter Field:=2, Criteria1:=Array("=*MY 18*", "=*MY18*", "<>*discussion*")

Upvotes: 1

Related Questions