VBA code to scan worksheet for values and highlight matches

rockstarlive

New Member
Joined
Jun 10, 2013
Messages
2
The problem is conditional formatting only allows me to search for one value, while I need to lookup a range of values. This is the macro I've been using:

Sub ABC()

Dim vntWords As Variant
Dim lngIndex As Long
Dim rngFind As Range
Dim strFirstAddress As String
Dim lngPos As Long

vntWords = Array("Adult", "Air", "Art", "Association", "Award", "Bar", "Bribe", "Campaign", "Candidate", "Cash", "Cash Advance", "Charitable", "Charities", "Charity", "City", "Civic", "Commission", "Community", "Compensation", "Conference", "Contribute", "Contribution", "Contributions", "Convenience", "Culture", "Customer")

With ActiveSheet.UsedRange
For lngIndex = LBound(vntWords) To UBound(vntWords)
Set rngFind = .Find(vntWords(lngIndex), LookIn:=xlValues, lookat:=xlPart)
If Not rngFind Is Nothing Then
strFirstAddress = rngFind.Address
Do
lngPos = 0
Do
lngPos = InStr(lngPos + 1, rngFind.Value, vntWords(lngIndex), vbTextCompare)
If lngPos > 0 Then
With rngFind.Characters(lngPos, Len(vntWords(lngIndex)))
.Font.Bold = True
.Font.Size = .Font.Size + 2
.Font.ColorIndex = 3
End With
End If
Loop While lngPos > 0
Set rngFind = .FindNext(rngFind)
Loop While rngFind.Address <> strFirstAddress
End If
Next
End With

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Greetings and welcome to the site :)

I am afraid that your question is unclear, at least to me.

Mark
 
Upvote 0
Greetings and welcome to the site :)

I am afraid that your question is unclear, at least to me.

Mark

Have a look at this formula:
=IF(SUMPRODUCT(COUNTIF(A9:AU9,"*"&Keywords!$A$5:$A$78&"*")),"POTENTIAL", "")

This gives a partial match but I need an exact match
 
Upvote 0

Forum statistics

Threads
1,215,949
Messages
6,127,888
Members
449,411
Latest member
AppellatePerson

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