Hi all.
I use the following code to highlight in red, certain keywords which appear in a sheet.
There are many more, but I have just shortened it for this purpose.
It works well, but it will highlight anything which contains the word e.g TEA
Like STEAM MOP.
Or BOOKCASE and not just BOOK
Is there a way to just highlight the specific word I have in the Comments
Thanks for looking
Regards,
Graham
I use the following code to highlight in red, certain keywords which appear in a sheet.
There are many more, but I have just shortened it for this purpose.
It works well, but it will highlight anything which contains the word e.g TEA
Like STEAM MOP.
Or BOOKCASE and not just BOOK
Is there a way to just highlight the specific word I have in the Comments
VBA Code:
Dim ws As Worksheet
Dim Match As Range
Dim Comment() As String
Set ws = ActiveWorkbook.Worksheets(1)
ReDim Comment(3)
Comment(0) = "TEA"
Comment(1) = "COFFEE"
Comment(2) = "BOOK"
For i = LBound(Comment) To UBound(Comment)
Set Match = ws.Cells.Find(What:=Comment(i), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not Match Is Nothing Then
FirstAddress = Match.Address
Do
sPos = InStr(1, Match.Value, Comment(i))
sLen = Len(Comment(i))
Match.Characters(Start:=sPos, Length:=sLen).Font.Color = RGB(255, 0, 0) ‘Red
Match.Interior.Color = RGB(153, 255, 153) 'Green
Set Match = ws.Cells.FindNext(Match)
Loop While Not Match Is Nothing And Match.Address <> FirstAddress
End If
Next
Thanks for looking
Regards,
Graham