Solved

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

Posted on 2014-11-24
13
106 Views
Last Modified: 2014-11-24
I would like to change the font color of the first character in a string within a cell.  Can this be done?
0
Comment
Question by:tballin
  • 7
  • 4
  • 2
13 Comments
 
LVL 39

Expert Comment

by:als315
ID: 40462275
You should have no problems if you will do it manually. How do you like to accomplish this?
0
 

Author Comment

by:tballin
ID: 40462297
I would like to setup a formatting rule - there's just too many cells to do this manually.
0
 
LVL 39

Expert Comment

by:als315
ID: 40462311
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?
0
 

Author Comment

by:tballin
ID: 40462350
A macro will work.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40462412
Sub HighLightCell()

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

End Sub
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40462414
Or
Sub HighLightCell()

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

End Sub
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:tballin
ID: 40462468
When I run this, the entire cell takes on the new format, not just the first character.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40462479
Did you copy it correctly? This is what I see.
?
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40462491
Or the following where I did Range("A1").Characters(1, 1).Font.Size = 24.
??
0
 

Author Comment

by:tballin
ID: 40462621
I might be copying it wrong... but here's what I'm seeing:

code.JPGsheet.JPG
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40462640
Hmmm. It seems that it does that for numbers. Let me see what I can do.
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40462682
Sorry but if it's a number (even formatted as text) I don't think it can be done.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40462838
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

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now