Highlight Text

Welsh Mark3

Board Regular
Joined
Apr 7, 2014
Messages
164
Office Version
  1. 365
I have a column of notes - lets say this is column A. I want to highlight just part of the the text. In this case it just "#addingvalue"

I can use the Conditional formatting function but to my knowledge it highlights the entire cell, I just want to highlight of change color of text just for the phase shown above.
 
The range will remain the same, I am potentially looking for multiple strings from the same cells and to highlight them differently. For example #addingvalue = Red
Health check = Green
Additional = Blue

The specific colors are not important more so that they are different by string
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Also do you want all the strings the same colour?
 
Upvote 0
Ok, try
Code:
Sub WelshMark3()
   Dim Cl As Range
   Dim x As Long, i As Long
   Dim Ary As Variant
   
   Ary = Array("#addingvalue", "[COLOR=#0000ff]and[/COLOR]", "[COLOR=#0000ff]east[/COLOR]", "[COLOR=#0000ff]town north[/COLOR]")
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      For i = 0 To UBound(Ary)
         x = InStr(1, Cl.Value, Ary(i), vbTextCompare)
         If x > 0 Then Cl.Characters(x, Len(Ary(i))).Font.ColorIndex = Choose(i + [COLOR=#ff0000]1, 3, 4, 5, 46[/COLOR])
      Next i
   Next Cl
End Sub
Change values in blue to match your strings & add more if needed.
Change the values in red to match the colour index you want.
List of colourindex numbers can be found here http://dmcritchie.mvps.org/excel/colors.htm
 
Upvote 0
Ok, try
Code:
Sub WelshMark3()
   Dim Cl As Range
   Dim x As Long, i As Long
   Dim Ary As Variant
   
   Ary = Array("#addingvalue", "[COLOR=#0000ff]and[/COLOR]", "[COLOR=#0000ff]east[/COLOR]", "[COLOR=#0000ff]town north[/COLOR]")
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      For i = 0 To UBound(Ary)
         x = InStr(1, Cl.Value, Ary(i), vbTextCompare)
         If x > 0 Then Cl.Characters(x, Len(Ary(i))).Font.ColorIndex = Choose(i + [COLOR=#ff0000]1, 3, 4, 5, 46[/COLOR])
      Next i
   Next Cl
End Sub
Change values in blue to match your strings & add more if needed.
Change the values in red to match the colour index you want.
List of colourindex numbers can be found here http://dmcritchie.mvps.org/excel/colors.htm

Thank you very much this is extremely useful
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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