Search for a column and filter 3 or more names with wildcards

dpchheda

New Member
Joined
Oct 31, 2011
Messages
8
Hi Friends, I request your help here for a code to search for a column using column name and filter data using wildcards. ABC, PQR, and XYZ are part of the same team but no other column to identify teams and therefore they need to be searched at once from the given data.

Below code was generated by a macro. I tried to tweak it but I am not able to get my head around it and its not working as planned.

Sub Filter_DC()
Cells.Find(What:="Name", LookAt:=xlWhole).Activate
Selection.AutoFilter
ActiveSheet.Range("A1:V1000").AutoFilter Field:=14, Criteria1:=Array("*ABC*", "*PQR*", "*XYZ*"), Operator:=xlFilterValues
Cells.Find(What:="Name").Select
End Sub

Please help.
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,276
Office Version
  1. 365
Platform
  1. Windows
You can only filter with an array for exact matches, not partial matches.
How about
VBA Code:
Sub dpchheda()
   Dim Fnd As Range, Cl As Range
   
   Set Fnd = Range("1:1").Find("Name", , , xlWhole, , , False, , False)
   If Fnd Is Nothing Then Exit Sub
   With CreateObject("scripting.dictionary")
      For Each Cl In Range(Fnd, Cells(Rows.Count, Fnd.Column).End(xlUp))
         If InStr(1, Cl, "abc", vbTextCompare) > 0 Or InStr(1, Cl, "pqr", vbTextCompare) > 0 Or InStr(1, Cl, "xyz", vbTextCompare) > 0 Then
            .Item(Cl.Value) = Empty
         End If
      Next Cl
      Range("1:1").AutoFilter Fnd.Column, .Keys, xlFilterValues
   End With
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,276
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,127,063
Messages
5,622,470
Members
415,897
Latest member
Barry18180

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
Top