Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Differnt colors in one cell?

9 views
Skip to first unread message

David McRitchie

unread,
Jan 12, 2000, 3:00:00 AM1/12/00
to
Hi Calle,
You cannot color individual parts of a formula and you cannot
color individual letters or groups within a cell using VBA.

HTH,
David McRitchie, Microsoft MVP - Excel
My Excel Pages: http://members.aol.com/dmcritchie/excel/excel.htm

Calle Bokedal <calle_...@hotmail.com> wrote in message news:85je21$3eo$1...@yggdrasil.utfors.se...
Is it possible to have different colors for differents characters in
one cell (in Excel 97)?
I tried to do it manually, and it seems to work when I'm changing color for some chars, but when I confirm (with Enter), all
characters change color.

Thanks!
Calle


Tom Ogilvy

unread,
Jan 12, 2000, 3:00:00 AM1/12/00
to
David,

>you cannot
> color individual letters or groups within a cell using VBA.

Maybe I am misunderstanding your statement, but this colors individual
letters of a text string in a cell for me - I agree about not being able to
do this with a formula generated string.

Dim rng As Range
Dim i As Long
Dim strLen As Long
Set rng = ActiveCell
strLen = Len(rng.Value)
For i = 1 To strLen
rng.Characters(Start:=i, Length:=1).Font.ColorIndex _
= Rnd() * 56 + 1
Next
End Sub

Regards,
Tom Ogilvy
MVP Excel

David McRitchie <DMcRi...@msn.com> wrote in message
news:#2cTAeXX$GA.70@cpmsnbbsa04...

Chip Pearson

unread,
Jan 12, 2000, 3:00:00 AM1/12/00
to
"David McRitchie" <DMcRi...@msn.com> wrote in message
> and you cannot
> color individual letters or groups within a cell using VBA.

Of course you can, as long as the cell doesn't contain a formula. If the
cell contains a constant, then you can do something like:

Range("A1").Characters(3, 5).Font.Color = vbRed
Range("A1").Characters(8, 3).Font.Color = vbGreen

Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting Services
www.cpearson.com ch...@cpearson.com

Chip Pearson

unread,
Jan 12, 2000, 3:00:00 AM1/12/00
to
Tom's code make much prettier colors than my code does. The cell looks like
a string of Christmas lights.

Users will love it!

Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting Services
www.cpearson.com ch...@cpearson.com


"Tom Ogilvy" <twog...@email.msn.com> wrote in message
news:um2EN7XX$GA....@cppssbbsa02.microsoft.com...
> David,


>
> >you cannot
> > color individual letters or groups within a cell using VBA.
>

> Maybe I am misunderstanding your statement, but this colors individual
> letters of a text string in a cell for me - I agree about not being able
to
> do this with a formula generated string.
>
> Dim rng As Range
> Dim i As Long
> Dim strLen As Long
> Set rng = ActiveCell
> strLen = Len(rng.Value)
> For i = 1 To strLen
> rng.Characters(Start:=i, Length:=1).Font.ColorIndex _
> = Rnd() * 56 + 1
> Next
> End Sub
>
> Regards,
> Tom Ogilvy
> MVP Excel
>
>
>

Chip Pearson

unread,
Jan 12, 2000, 3:00:00 AM1/12/00
to
Run Tom's code via Application.OnTime, and they'll really twinkle!

Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting Services
www.cpearson.com ch...@cpearson.com

"David McRitchie" <DMcRi...@msn.com> wrote in message

news:ekCSpXYX$GA.273@cpmsnbbsa04...
> I am amazed at both Chip's and Tom's replies. I also like Chip's
> Christmas light analogy which I can relate with broken bulbs when
> the random number generates a color matching the background <grin>.

Calle Bokedal

unread,
Jan 13, 2000, 3:00:00 AM1/13/00
to

David McRitchie

unread,
Jan 13, 2000, 3:00:00 AM1/13/00
to
0 new messages