Highlight the exact value

S

ste mac

Hi, the macro below is curtesy of this ng.

The only problem is that if a value to hightlight
is say, a '7' it will hightlight '17' I presume that
this is because there is a '7' in '17' ...

Can any kind soul alter the code so it highlights
the exact values in the range please as I may have
to hightlight as many as 20 values in 18,000

cheers, ste

Sub colourrowsin()
Dim i As Long
Dim Lookupvalue
Dim c As Variant
'Clear the current range
Range("A3:A52").Select
Selection.Interior.ColorIndex = xlNone

For i = 2 To 7 ' Look at values in T2 to T7
Lookupvalue = Cells(i, 20).Value
'{Search A3:A52 for a match to Lookupvalue}
With Range("A3:A52")
Set c = .Find(Lookupvalue)
If Not c Is Nothing Then
'(if match then highlight the cell in range}
Range(c.Address).Select
With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
End If
End With
Next

End Sub
 
B

Bob Phillips

Change

Set c = .Find(Lookupvalue)

to

Set c = .FindWhat:=Lookupvalue, LookAt:=xlWhole)


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top