VBA - Searching for Strings with Wildcard Values

beartooth91

Board Regular
Joined
Dec 15, 2024
Messages
64
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hello

Here's an easy one (just not easy for me!): I have a list of data where I have tag information where some have wildcard characters present in the tag name. All I'm wanting to do is highlight the cells with alphanumeric strings containing # or ?

1NSSLI001-SEL (proper name, do not highlight)

1NSSLI####X (highlight)

1NSS??#### (highlight)

1NSSLI001-? (highlight)

1-NSS-??-#### (highlight)

I know that VBA is flakey when searching for strings containing wildcard values and my code, below, is highlighting even the proper names......

VBA Code:
For Each cell In .Range("R11:R" & lr)
    If cell.Value Like "*####*" Then
       cell.Interior.ColorIndex = 22
       cell.Offset(, -16).Interior.ColorIndex = 6
    ElseIf cell.Value Like "*?*" Then
       cell.Interior.ColorIndex = 22
       cell.Offset(, -16).Interior.ColorIndex = 6
    ElseIf cell.Value Like "NOT FOUND" Then
       cell.Interior.ColorIndex = 22
       cell.Offset(, -16).Interior.ColorIndex = 6
    End If
  Next cell
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
This seems to work.....
VBA Code:
For Each cell In .Range("R11:R" & lr)
    If InStr(3, cell, "#") Then
       cell.Interior.ColorIndex = 22
       cell.Offset(, -16).Interior.ColorIndex = 6
    ElseIf InStr(3, cell, "?") Then
       cell.Interior.ColorIndex = 22
       cell.Offset(, -16).Interior.ColorIndex = 6
    ElseIf cell.Value Like "NOT FOUND" Then
       cell.Interior.ColorIndex = 22
       cell.Offset(, -16).Interior.ColorIndex = 6
    End If
  Next cell
 
Upvote 0

Forum statistics

Threads
1,225,626
Messages
6,186,087
Members
453,336
Latest member
Excelnoob223

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