Auto Filter text that contains...

tennis07

Board Regular
Joined
Apr 29, 2015
Messages
57
Hi Guys,
How can I create an autofilter in many columns that contains an specific text.
If I do something like that (below), the return will be empty because it works like an AND operator and I want to work with OR.
Column B = Red OR Column C = Red

ActiveSheet.Range("$A$1:$E$1000").AutoFilter Field:=1, Criteria1:= _
"Red", Operator:=xlOr, Field:=2, Criteria2:="Red"

How can I get a result like the image attached?

Any help?

Thanks in advance
 

Attachments

  • FilterText.png
    FilterText.png
    23.3 KB · Views: 8

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi,​
for an 'OR' operator between columns you have two choices :​
  1. a helper column with a formula

  2. an advanced filter …
 
Upvote 0
Try Advanced Filter with a formula as criterion

Something like this
VBA Code:
Sub AdvFilter()
    Range("G1").Value = "Formula"
    Range("G2").Formula = "=MATCH(""Red"",B2:C2,0)"
    Range("A1:E21").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "G1:G2"), CopyToRange:=Range("K1:O1"), Unique:=False
End Sub

Hope this helps

M.
 
Upvote 0
Try Advanced Filter with a formula as criterion

Something like this
VBA Code:
Sub AdvFilter()
    Range("G1").Value = "Formula"
    Range("G2").Formula = "=MATCH(""Red"",B2:C2,0)"
    Range("A1:E21").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "G1:G2"), CopyToRange:=Range("K1:O1"), Unique:=False
End Sub

Hope this helps

M.
 
Upvote 0
Marcelo,

thanks a lot.

Another question...How can I replace the "red" text for a variable instead?
=MATCH(variable, range,0)
 
Upvote 0
Another question...How can I replace the "red" text for a variable instead?
=MATCH(variable, range,0)

Try
VBA Code:
Sub AdvFilter()
    Dim myVal As String
    
    myVal = "Red"
    Range("G1").Value = "Formula"
    Range("G2").Formula = "=MATCH(""" & myVal & """,B2:C2,0)"
    Range("A1:E21").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "G1:G2"), CopyToRange:=Range("K1:O1"), Unique:=False
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top