Multiple Text Colors in Same Cell

M

matthew.nagowski

Hello --

I am wondering if there is a way to format a cell so that multiple
colors can be assigned to different text within the cell.

I am trying to construct a simple in-cell bar chart representing the
distribution of data across different categories, and want to be able
to distinguish across the different categories using colors.

For instance, this would create a two category bar chart, but I have
no way to distinguish between the first category and the second
category:

=REPT(A1,A2)&REPT(A1,B2)

Is there any function (e.g. COLOR() ) that would be able to do the
following:

=COLOR(REPT(A1,A2),SOMECOLOR)&COLOR(REPT(A1,B2),SOMECOLOR)

Maybe there is something in VBA?
 
D

Dave Peterson

If the cell contains a formula, you can't do this character by character
formatting.

But if you convert it to values, you can select your characters (in the
formulabar) and then format them the way you want.

Could you use multiple lines within the cell:

=REPT(A1,A2)&char(10)&REPT(A1,B2)
(and turn on wrap text)
 
B

Brian Withun

You can assign different colors to different areas of text within a
single cell using VBA:

This code puts "Test cell value" into cell B5, then colors the word
"Test" blue (5) and the colors the word "cell" red (3)

Range("B5").Select
ActiveCell.FormulaR1C1 = "Test cell value"
With ActiveCell.Characters(Start:=1, Length:=4).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 5
End With
With ActiveCell.Characters(Start:=5, Length:=1).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With ActiveCell.Characters(Start:=6, Length:=4).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 3
End With

I hope this helps!

Brian Herbert Withun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top