PC Review


Reply
Thread Tools Rate Thread

Color a part of a cell...

 
 
=?Utf-8?B?VGlhZ28=?=
Guest
Posts: n/a
 
      28th May 2007
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

 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      28th May 2007
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" <(E-Mail Removed)> wrote in message news:AB7B8531-B85A-4469-B599-(E-Mail Removed)...
> 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
>

 
Reply With Quote
 
=?Utf-8?B?VGlhZ28=?=
Guest
Posts: n/a
 
      28th May 2007
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" <(E-Mail Removed)> wrote in message news:AB7B8531-B85A-4469-B599-(E-Mail Removed)...
> > 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
> >

>

 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      28th May 2007
On Mon, 28 May 2007 04:23:00 -0700, Tiago <(E-Mail Removed)>
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
 
Reply With Quote
 
=?Utf-8?B?ZXhjZWxlbnQ=?=
Guest
Posts: n/a
 
      28th May 2007
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" <(E-Mail Removed)> wrote in message news:AB7B8531-B85A-4469-B599-(E-Mail Removed)...
> > > 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
> > >

> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
scan text in cell and color part of the text mrom34 Microsoft Excel Programming 0 29th Apr 2010 08:01 PM
How to change cell background color as part of the If statement? Jim H Microsoft Excel Worksheet Functions 2 23rd Sep 2009 11:58 PM
Re: format color of text in part of a cell Bernard Liengme Microsoft Excel Misc 0 4th Jan 2007 05:09 PM
Re: format color of text in part of a cell Bernard Liengme Microsoft Excel Misc 0 4th Jan 2007 04:02 PM
Change font/color of part of the text in a cell in windows datagrid Garima Sajwan Microsoft Dot NET Framework Forms 0 30th Jun 2004 11:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:16 PM.