Search for and Higlight text within a cell

  • Thread starter Thread starter John Fevens
  • Start date Start date
J

John Fevens

I am looking for a way to search through a workbook of multiple
sheets, looking in one of the columns for a list of keywords.

If the keyword is located, I want to change the colour of the text
matching the keywords, or just change the background colour of the
entire cell.

There will be a series of 5 or 6 groups of keywords, each representing
a different colour.
 
Hi John
try something like the following

sub change_color()
Dim rng as range
Dim cell as range
Set rng = ActiveSheet.Usedrange
for each cell in rng
With cell.value
Select Case .Value
Case "keyword 1": .Interior.ColorIndex = 3
Case "keyword 2": .Interior.ColorIndex = 10
'etc.
End Select
End With
next
End Sub
 
That is simalar to what I need, but I need to look at text within the
cell, that seems to only work if the keyword is the only string in the
cell.

Unless perhaps I am not using it right!
 
O.k.
try

sub change_color()
Dim rng as range
Dim cell as range
Set rng = ActiveSheet.Usedrange
for each cell in rng
With cell.
if instr(.value, "keyword1") then
.Interior.ColorIndex = 3
elseif instr(.value, "keyword2") then
.Interior.ColorIndex = 10
'etc
end if
End With
next
End Sub
 

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

Back
Top