Filtering on multiple criteria not working

Neild137

New Member
Joined
Mar 23, 2017
Messages
48
I have the following code, which I would like to expand. I would like the data to be filtered down to anything that starts with the letter F in column 113 and certain things that start with the letter V. I would like to expand upon this, to include a list of about 23 allowable criteria that start with V, but I am already running into roadblocks.

Any clue how to solve this?

Code:
Sub filter2()
    
    
    Dim Lastrow As Long
    Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
  
  With ActiveSheet.Range("A1:EN" & Lastrow)
    If ActiveSheet.FilterMode Then .AutoFilter
    .AutoFilter Field:=113, Criteria1:=Array("F***"), Operator:=xlOr, Criteria2:=Array("VMMA", "VMMB", "VMMC, "VMME")

  End With
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
When using wildcards you can only have 2 values for the autofilter.
One option is this
Code:
Sub filter2()
    
    
    Dim UsdRws As Long
    Dim Fltr As Variant
    Dim Val As Variant
    Dim Cl As Range
    Dim Dict As Object
    
    UsdRws = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    Set Dict = CreateObject("scripting.dictionary")
    Fltr = Array([COLOR=#0000ff]"F*", "ARX", "ADSL", "TSC2"[/COLOR])
  
    With ActiveSheet
        .FilterMode = False
        For Each Val In Fltr
            For Each Cl In .Range("[COLOR=#0000ff]E2:E"[/COLOR] & UsdRws)
                If Cl.Value Like Val Then Dict(Cl.Value) = vbNullString
            Next Cl
        Next Val
    .Range("A1:EN" & UsdRws).AutoFilter field:=[COLOR=#0000ff]5[/COLOR], Criteria1:=Dict.keys, Operator:=xlFilterValues
  End With
End Sub
Change the values in blue to match your needs
 
Upvote 0
Slight rethink on this, are most of your criteria hard values (ie no wildcards)?
 
Upvote 0
Please take a minute to read the forum rules, especially relating to cross-posting, and then comply with them. Thank you.

An advanced filter would probably be easier for this.
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,635
Members
452,661
Latest member
Nonhle

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