VBA filter columns by values and wildcards

DutchKevin

Board Regular
Joined
Apr 13, 2011
Messages
133
Office Version
  1. 365
Platform
  1. Windows
Hello All,
For a table that i have I use below code to filter based on column titels. Showing only columns that meat the criteria in row 8.
However this currently only works for an exact match (I already managed to get around the case sensitivity).

I would need a code that filters for part of the vaulue.
Lets say I enter "Text1" as a search criteria in cell C8, I need the code to show all colums where in row 8 the "text1" is part of the value. So showing also "text11" and Text1A" for example.
I can't get my head around how to use the wildcards properly.
Do you have any suggestions??

Thanks
Kevin

Code:
            If (LCase(Cells(8, n).Value)) = LCase(Range("c8").Value) Then  'note the explicit Lowercase command
                Cells(8, n).EntireColumn.Hidden = False
            Else: Cells(8, n).EntireColumn.Hidden = True
            End If
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Perhaps like this

Code:
            If LCase(Cells(8, n).Value) Like LCase(Range("C8").Value) & "*" Then  'note the explicit Lowercase command
                Cells(8, n).EntireColumn.Hidden = False
            Else: Cells(8, n).EntireColumn.Hidden = True
            End If
 
Upvote 0
Hi Peter,
Thanks for the try, but it's not producing any results on the filter. Outcome is empty so to speak.
I had myself also tried various options with the [& "*"] but also without results.

Also this one has same effect.

Code:
            If (LCase(Cells(8, n).Value)) = LCase(Range("*" & "c8" & "*").Value) Then            'note the explicit Lowercase command
                Cells(8, n).EntireColumn.Hidden = False
            Else: Cells(8, n).EntireColumn.Hidden = True
            End If

BR
Kevin
 
Last edited:
Upvote 0
Then maybe

Code:
            If LCase(Cells(8, n).Value) Like "*" & LCase(Range("C8").Value) & "*" Then  'note the explicit Lowercase command
                Cells(8, n).EntireColumn.Hidden = False
            Else: Cells(8, n).EntireColumn.Hidden = True
            End If
 
Upvote 0
:)

Thanks Peter! that worked!
The "like" did the the trick.

Merry Christmas and a happy new year to you and all other readers!
 
Upvote 0

Forum statistics

Threads
1,216,730
Messages
6,132,402
Members
449,725
Latest member
Enero1

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