Link to home
Start Free TrialLog in
Avatar of tballin
tballin

asked on

How to format the first character of a string in an Excel 2010 cell

I would like to change the font color of the first character in a string within a cell.  Can this be done?
Avatar of als315
als315
Flag of Russian Federation image

You should have no problems if you will do it manually. How do you like to accomplish this?
Avatar of tballin
tballin

ASKER

I would like to setup a formatting rule - there's just too many cells to do this manually.
You can't do it with formatting rule, because in these rules you can change colors only in whole cell, but you can do it with macro. Is it acceptable?
Avatar of tballin

ASKER

A macro will work.
Sub HighLightCell()

    Range("A1").Characters(1, 1).Font.Color = vbRed

End Sub
Or
Sub HighLightCell()

    Range("A1").Characters(1, 1).Font.Bold = True 'etc.

End Sub
Avatar of tballin

ASKER

When I run this, the entire cell takes on the new format, not just the first character.
Did you copy it correctly? This is what I see.
User generated image
Or the following where I did Range("A1").Characters(1, 1).Font.Size = 24.
User generated image
Avatar of tballin

ASKER

I might be copying it wrong... but here's what I'm seeing:

User generated imageUser generated image
Hmmm. It seems that it does that for numbers. Let me see what I can do.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This does it
Sub HighLightCell()

    Range("A2").Value = "'" & Range("A2").Value
    Range("A2").Characters(1, 1).Font.Color = vbRed
    Range("A2").HorizontalAlignment = xlRight
    
End Sub

Open in new window