Change Colour of Specific Words in cells

christian2016

Board Regular
Joined
Oct 6, 2016
Messages
123
Hi Guys,

What I need help with is a VBA macro to find the total range of say Column C.

Column C each cell will have a paragraph of text.

Then need to loop that range looking for specific words say (OFF, ON, UP, DOWN).
Probably best to temporarily set the cell text as UPPER case so no need to search for a combination of upper and lower case words.

If the text has been found then change only that specific word in the cell text to RED and BOLD.

Then go to the next cell in our range and repeat.

Any help is greatly appreciated.

Thanks
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub ColorWords()
  Dim Position As Long, Cell As Range, W As Variant, Words As Variant, Txt As String
  Words = Array("TEXT", "WORD", "THEN")
  For Each Cell In Columns("C").SpecialCells(xlConstants)
    Txt = " " & UCase(Cell.Value) & " "
    For Each W In Words
      Position = InStr(Txt, W)
      Do While Position > 0
        If Mid(Txt, Position - 1, Len(W) + 2) Like "[!A-Z0-9]" & W & "[!A-Z0-9]" Then
          With Cell.Characters(Position - 1, Len(W)).Font
            .Bold = True
            .Color = vbRed
          End With
        End If
        Position = InStr(Position + 1, Txt, W)
      Loop
    Next
  Next
End Sub[/td]
[/tr]
[/table]
Note: This only highlights the word if it is a stand-alone non-embedded word.
 
Upvote 0
Thank you Rick works well.

Sorry i forgot to mention what happens if my range is say from column C to Column J. How Do I amend the macro to work across all these columns.
 
Upvote 0
Thank you Rick works well.

Sorry i forgot to mention what happens if my range is say from column C to Column J. How Do I amend the macro to work across all these columns.
Just change this line of code...

For Each Cell In Columns("C").SpecialCells(xlConstants)

to this...

For Each Cell In Columns("C:J").SpecialCells(xlConstants)
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,589
Members
452,653
Latest member
craigje92

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