Format single character

A

alex

Hello All,

Using Excel '07...

Is there a way to use conditional formatting (or something else) to
color a single character in a string.

E.g., change the color of the fifth character in a cell?

alex
 
R

Ron Rosenfeld

Hello All,

Using Excel '07...

Is there a way to use conditional formatting (or something else) to
color a single character in a string.

E.g., change the color of the fifth character in a cell?

alex

Only if it is a string, and not the result of a formula.

Select the cell and go into edit mode. Then select the character and format
it.

This could also be done with VBA:

To enter this Macro (Sub), <alt-F11> opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this Macro (Sub), <alt-F8> opens the macro dialog box. Select the macro
by name, and <RUN>.

=========================
Option Explicit
Sub Red5Char()
Dim c As Range
Set c = Selection
If c.Count <> 1 Then Exit Sub
If Len(c.Text) < 5 Then Exit Sub
c.Characters(5, 1).Font.Color = vbRed
End Sub
==========================
--ron
 
A

alex

Only if it is a string, and not the result of a formula.

Select the cell and go into edit mode.  Then select the character and format
it.

This could also be done with VBA:

To enter this Macro (Sub), <alt-F11> opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this Macro (Sub), <alt-F8> opens the macro dialog box. Select the macro
by name, and <RUN>.

=========================
Option Explicit
Sub Red5Char()
Dim c As Range
Set c = Selection
If c.Count <> 1 Then Exit Sub
If Len(c.Text) < 5 Then Exit Sub
c.Characters(5, 1).Font.Color = vbRed
End Sub
==========================
--ron

Thanks for your input, Ron.

This xls doc is a simple calculator that sits on a user's desktop.
The user enters different numbers (8 char long) throughout the day
into the same cell (only one number at a time). I would like the fith
character of any number to become a certain color whenever it's typed.

I'll play around with the VBA code that you provided. I don't want
the user to have to envoke a marcro...

alex
 
R

Ron Rosenfeld

Thanks for your input, Ron.

This xls doc is a simple calculator that sits on a user's desktop.
The user enters different numbers (8 char long) throughout the day
into the same cell (only one number at a time). I would like the fith
character of any number to become a certain color whenever it's typed.

I'll play around with the VBA code that you provided. I don't want
the user to have to envoke a marcro...

alex

Alex,

I don't think you can do that.

You could certainly use event code to avoid your user having to execute a
macro. However, the formatting will not take place until after the entire
number has been entered into the cell. I don't know how to format the digits
as they are being entered.

--ron
 

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