ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   format color of text in part of a cell (https://www.excelbanter.com/excel-discussion-misc-queries/124657-format-color-text-part-cell.html)

b4nature

format color of text in part of a cell
 
I want to change the color of part of a string of text in a cell, not the
whole cell. I know I need a macro but am not a knowledgeable VB user.

Would someone be willing to share code with me that would change the color
of the word "no" to red when found within a string in a select group of cells.

Hopefully what I am asking makes sense!
Thank you!

galimi

format color of text in part of a cell
 
I have provided an example at http://HelpExcel.com/examples
The name of the file is colorNo.xls
--
http://HelpExcel.com




"b4nature" wrote:

I want to change the color of part of a string of text in a cell, not the
whole cell. I know I need a macro but am not a knowledgeable VB user.

Would someone be willing to share code with me that would change the color
of the word "no" to red when found within a string in a select group of cells.

Hopefully what I am asking makes sense!
Thank you!


Bernard Liengme

format color of text in part of a cell
 
Sub RedNose()
Set myrange = Selection
For Each mycell In myrange
k = InStrRev(UCase(mycell), "NO")
If k 0 Then
mycell.Characters(Start:=k, Length:=2).Font.ColorIndex = 3
End If
Next
End Sub

select the range to process and run the macro from Tools | Macro | Macros
best wishes
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"b4nature" wrote in message
...
I want to change the color of part of a string of text in a cell, not the
whole cell. I know I need a macro but am not a knowledgeable VB user.

Would someone be willing to share code with me that would change the color
of the word "no" to red when found within a string in a select group of
cells.

Hopefully what I am asking makes sense!
Thank you!




Bernard Liengme

format color of text in part of a cell
 
I expect you want only the isolated word "no" in red, so I have modified the
code

Sub RedNose()
Set myrange = Selection
For Each mycell In myrange
k = InStrRev(UCase(mycell), "NO")
If Mid(mycell, k + 2, 1) < " " Then k = 0
If k 1 Then
If Mid(mycell, k - 1, 1) < " " Then k = 0
End If
If k 0 Then
mycell.Characters(Start:=k, Length:=2).Font.ColorIndex = 3
End If
Next
End Sub

--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"b4nature" wrote in message
...
I want to change the color of part of a string of text in a cell, not the
whole cell. I know I need a macro but am not a knowledgeable VB user.

Would someone be willing to share code with me that would change the color
of the word "no" to red when found within a string in a select group of
cells.

Hopefully what I am asking makes sense!
Thank you!





All times are GMT +1. The time now is 01:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com