I need to filter a data table where 3 columns can contain the result I am looking for:
So if the criteria is found in columns 1, 2 or 3 then the row should be returned.
Data http://im69.gulfup.com/gBZHK.png
So in the above sample data lets say I select the criteria as "Fat"
I am looking for the autofilter to return rows 1 & 2; if I select the criteria as "Funny" I need rows 2 & 6 and so on....
Below is my code which is not working since apparently it tries to find the rows in which all columns contain the criteria, and it is not what I am looking to do.
With Sheet1
.AutoFilterMode = False
With .Range("A1:D6")
.AutoFilter
.AutoFilter Field:=2, Criteria1:="Fat", Operator:=xlFilterValues
.AutoFilter Field:=3, Criteria1:="Fat", Operator:=xlFilterValues
.AutoFilter Field:=4, Criteria1:="Fat", Operator:=xlFilterValues
End With
End With
I have also tried to use Operator:=xlor
but when I ran the code it returned no results.
In short: The row must be returned by the filter is the criteria is found in column B or C or D.
Help is definitely appreciated.
As follow up from comments, there are two ways for you.
Use additional column with formula:
Use For loop with Union:
For copying also header:
UPDATE: