Filter range by multiple criteria

_Khalil_

New Member
Joined
May 27, 2014
Messages
2
Hi !

This is what I need to do:
I have a range (lista) that contains strings in column 2, and I want to filter it by those cells that contain any of the words in a string called myarray.
Being myarray for example {"one","two","three"}, i would need to filter lista by the cells that contain either "one" OR "two" OR "three".

This is what i have now but it filters data that contain only the first element of the array:

Code:
Sub FiltradoPrueba()
      Dim myarray As Variant
      myarray = Range("Conceptos").Value

      ActiveSheet.Range("LISTA").AutoFilter Field:=2, Criteria1:=myarray, Operator:=xlFilterValues

End Sub

I'd greatly appreciate any light on this.

Greetings from Uruguay.

Adrián
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try this:

G1 has exact heading of A1.
H1 has exact heading of B1.
H2 has *One*
H3 has *Two*
H4 has *Three*
Code:
Private Sub cmdAutoAdvFilter_MultipleCriteria_Click()
 Sheets("Sheet1").Select
 Range("B1").Select
 LastRecNum = Cells(Rows.Count, "B").End(xlUp).Row
 Dim LISTA As Range
 Set LISTA = ActiveSheet.Range("A1:B" & Trim(Str(LastRecNum)))
 rng.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range( _
   "G1:H4"), Unique:=False
End Sub
 
Upvote 0
It worked!! Thank u so much!!

I adapted your code to my spreadsheet this way:

Code:
Sub cmdAutoAdvFilter_MultipleCriteria_Click()
 Range("LISTA").Select
 Set Rng = ActiveSheet.Range("LISTA")
 Rng.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("Conceptos"), Unique:=False
End Sub
 
Upvote 0
Hi !

This is what I need to do:
I have a range (lista) that contains strings in column 2, and I want to filter it by those cells that contain any of the words in a string called myarray.
Being myarray for example {"one","two","three"}, i would need to filter lista by the cells that contain either "one" OR "two" OR "three".

This is what i have now but it filters data that contain only the first element of the array:

Code:
Sub FiltradoPrueba()
      Dim myarray As Variant
      myarray = Range("Conceptos").Value

      ActiveSheet.Range("LISTA").AutoFilter Field:=2, Criteria1:=myarray, Operator:=xlFilterValues

End Sub

I'd greatly appreciate any light on this.

Greetings from Uruguay.

Adrián

Try

Code:
Sub FiltradoPrueba()
      Dim myarray As Variant
      myarray = Application.Transpose(Range("Conceptos"))
      ActiveSheet.Range("LISTA").AutoFilter Field:=2, Criteria1:=myarray, Operator:=xlFilterValues
End Sub

M.
 
Upvote 0
Thanks for the reply. Glad to know that it worked. Good that you have adapted it to your need.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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