![]() |
Color a part of a cell...
Good Day,
I have a cell with this text: "1 - aaaaaaaa 2 - bbbbbbbb 3 - ccccccccc" how to color in red, just the "1-, 2- and 3-" anyone help? Thanks |
Color a part of a cell...
You can use this
Range("A1").Characters(Start:=1, Length:=2).Font.ColorIndex = 3 -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Tiago" wrote in message ... Good Day, I have a cell with this text: "1 - aaaaaaaa 2 - bbbbbbbb 3 - ccccccccc" how to color in red, just the "1-, 2- and 3-" anyone help? Thanks |
Color a part of a cell...
thkanks, it works....
"Ron de Bruin" wrote: You can use this Range("A1").Characters(Start:=1, Length:=2).Font.ColorIndex = 3 -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Tiago" wrote in message ... Good Day, I have a cell with this text: "1 - aaaaaaaa 2 - bbbbbbbb 3 - ccccccccc" how to color in red, just the "1-, 2- and 3-" anyone help? Thanks |
Color a part of a cell...
On Mon, 28 May 2007 04:23:00 -0700, Tiago
wrote: Good Day, I have a cell with this text: "1 - aaaaaaaa 2 - bbbbbbbb 3 - ccccccccc" how to color in red, just the "1-, 2- and 3-" anyone help? Thanks That can only be done if the text is an actual text string, and not the result of a function. The following will work assuming the leading number is a single digit as you have shown: ----------------------------- Option Explicit Sub ColorNum() Dim c As Range Dim str As String Dim i As Long Dim char As String Dim lRedLength As Long For Each c In Selection str = c.Text c.Font.Color = vbBlack 'or whatever the base color is For i = 1 To Len(str) char = Mid(str, i, Len(str) + 1 - i) If char Like "#*-?*" Then lRedLength = InStr(i, str, "-") - i + 1 c.Characters(i, lRedLength).Font.Color = vbRed i = i + lRedLength End If Next i Next c End Sub -------------------------------------- --ron |
Color a part of a cell...
Another way
select cell in formula-line select part u want colored and click color "Tiago" skrev: thkanks, it works.... "Ron de Bruin" wrote: You can use this Range("A1").Characters(Start:=1, Length:=2).Font.ColorIndex = 3 -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Tiago" wrote in message ... Good Day, I have a cell with this text: "1 - aaaaaaaa 2 - bbbbbbbb 3 - ccccccccc" how to color in red, just the "1-, 2- and 3-" anyone help? Thanks |
All times are GMT +1. The time now is 12:14 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com