VBA check if string contains character from list

Kra

Board Regular
Joined
Jul 4, 2022
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I am trying to set up macro which will detect character from list supplied by user in a cell value.

I have 2 sheets: "Data" and "Characters".

In "Characters" user will in write characters which they want to be detected (all in column A, no header). So lets say they want to detect capital O, dash and number 9.
A1 O
A2 -
A3 9

They will paste some report/data dump in sheet called "Data" and then macro will check each cell and highlight it on red if cell value contains any of characters given by user.
 
If I have understood correctly, then without looping through each character, each column and each row I think this should do it all at once.
I have assumed that the character list in column A of the 'Characters' sheet does not contain any blank cells.

VBA Code:
Sub CheckCharacters()
  With Sheets("Data").UsedRange
    .FormatConditions.Add Type:=xlExpression, Formula1:=Replace(Replace("=COUNT(FIND(Characters!$A$1:$A$#,^))", "#", Sheets("Characters").Cells(Rows.Count, 1).End(xlUp).Row), "^", .Cells(1, 1).Address(0, 0))
    .FormatConditions(1).Interior.Color = vbRed
  End With
End Sub
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,215,043
Messages
6,122,816
Members
449,095
Latest member
m_smith_solihull

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