Advance Filtering in VBA with multiple wildcard criterias

Tacty

New Member
Joined
Jul 12, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello everyone. working on a sheet that i would like to use some advance autofilters on with multiple wild cards.
basically when I click the program button it will filter out with wild cards on a specific column.

would like it to filter for

*Honda-CFW-6
*Honda-CFW-8
*Honda-CFW-3
*Honda-CFW-2
*Honda-CFW-1

though they will have more information following after, I would just like to filter for anything "containing" those following texts, even though they will have more information after it. Such as Honda-CFW-6122-555.

i have included a sample workbook, if anyone could show me how to get this started i would be greatful.
 

Attachments

  • 1122.png
    1122.png
    43.9 KB · Views: 14
k I made an example sheet closer to my data Dante.

Sorry, should of done this from the begginning.

Sheet

Your code that i'm using with some modifications
VBA Code:
Sub CommandButton1_Click()
  Dim a As Variant, b As Variant, arr() As Variant
  Dim i As Long, j As Long, k As Long, lr As Long
 
  If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
  lr = Range("G" & Rows.Count).End(3).Row
  Range("A3:Z" & lr).Sort Range("A4"), xlAscending, Header:=xlYes
  a = Range("A4:L" & lr).Value
  b = Range("AO3", Range("AO" & Rows.Count).End(3)).Value
 
  For i = 1 To UBound(a, 1)
    For j = 1 To UBound(b, 1)
      If a(i, 10) Like b(j, 1) & "*" Then
        k = k + 1
        ReDim Preserve arr(1 To k)
        arr(k) = a(i, 10)
      End If
    Next
  Next
  If k > 0 Then Range("A3:Z" & lr).AutoFilter 10, Array(arr), xlFilterValues
End Sub

Sample Excel.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAO
3Column1Column2Column3Column4Column5Column6Column7Column8Column9Column10Column11Column12Column13Column14Column15Column16Column17Column18Column19Column20Column21Column22Column23Column24Column25Column26Column7
4Honda-CFW-344-115Honda-CFW-3
5Honda-CFW-344-117Honda-CFW-8
6Honda-CFW-344-118Honda-CFW-1
7Honda-CFW-344-125
8Honda-CFW-346-119
9Honda-CFW-346-120
10Honda-CFW-446-121
11Honda-CFW-446-122
12Honda-CFW-444-123
13Honda-CFW-444-124
14Honda-CFW-347-126
15Honda-CFW-347-127
16Honda-CFW-348-131
17Honda-CFW-547-128
18Honda-CFW-548-129
19Honda-CFW-548-130
20Honda-CFW-348-132
21Honda-CFW-349-135
22Honda-CFW-354-116
23Honda-CFW-362-138
24Honda-CFW-362-144
25Honda-CFW-362-147
26Honda-CFW-362-148
27Honda-CFW-362-153
28Honda-CFW-362-154
29Honda-CFW-362-158
30Honda-CFW-382-152
31Honda-CFW-648-133
32Honda-CFW-649-134
33Honda-CFW-649-136
34Honda-CFW-962-145
35Honda-CFW-962-146
36Honda-CFW-662-137
37Honda-CFW-861-139
38Honda-CFW-262-149
39Honda-CFW-262-150
40Honda-CFW-281-151
41Honda-CFW-862-142
42Honda-CFW-862-143
43Honda-CFW-864-140
44Honda-CFW-162-155
45Honda-CFW-179-156
46Honda-CFW-177-157
47Honda-CFW-867-141
Sheet1
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
So, is it working now?
Hey Dante, Unfortunately no.

In my last messg I included a mini sheet closer to my actual document. take a look at it and see if you can modify/change the code.
 
Upvote 0
Sorry, should of done this from the begginning.
That's right, that's what you should do, since macros, particularly this macro, are not that dynamic and you have to tell exactly where the data is.

This is the updated macro with your model from post #11
VBA Code:
Sub CommandButton1_Click()
  Dim a As Variant, b As Variant, arr() As Variant
  Dim i As Long, j As Long, k As Long, lr As Long
  
  If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
  lr = Range("G" & Rows.Count).End(3).Row
  Range("A3:Z" & lr).Sort Range("G4"), xlAscending, Header:=xlYes
  a = Range("A4:Z" & lr).Value
  b = Range("AO4", Range("AO" & Rows.Count).End(3)).Value
  
  For i = 1 To UBound(a, 1)
    For j = 1 To UBound(b, 1)
      If a(i, 7) Like b(j, 1) & "*" Then
        k = k + 1
        ReDim Preserve arr(1 To k)
        arr(k) = a(i, 7)
      End If
    Next
  Next
  If k > 0 Then Range("A3:Z" & lr).AutoFilter 7, Array(arr), xlFilterValues
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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