PC Review


Reply
Thread Tools Rate Thread

Change color of characters in a cell based of a cell reference

 
 
kimbobo
Guest
Posts: n/a
 
      21st Mar 2008
Hi All,

Does anyone know how to change the color of characters in a cell based
of a cell reference.

For example, cell A1 = "||||||||||" (contains 10 "|") I want the first
4 "|" to be Red and the second 6 to Blue. Based of cells A2 = 4 and A3
= 6.

Any ideas?

Thanks!!

-Kim
 
Reply With Quote
 
 
 
 
ND Pard
Guest
Posts: n/a
 
      22nd Mar 2008
The following subprocedure (macro) will color the charactacters in column A,
beginning with cell A1 and going down until the value in column A is less
than " ", to the desired colors Red and Blue based on the column A's
respective values in columns B and C:

Sub Chg_Colors()
Range("A1").Select

Do While ActiveCell.Value > " "
ActiveCell.Characters(Start:=1, _
Length:=ActiveCell.Offset(0, 1).Value).Font.Color = -16777024
ActiveCell.Characters(Start:=ActiveCell.Offset(0, 1).Value + 1, _
Length:=ActiveCell.Offset(0, 2).Value).Font.Color = -10477568
ActiveCell.Offset(1).Select
Loop
End Sub

Good Luck.

"kimbobo" wrote:

> Hi All,
>
> Does anyone know how to change the color of characters in a cell based
> of a cell reference.
>
> For example, cell A1 = "||||||||||" (contains 10 "|") I want the first
> 4 "|" to be Red and the second 6 to Blue. Based of cells A2 = 4 and A3
> = 6.
>
> Any ideas?
>
> Thanks!!
>
> -Kim
>

 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      22nd Mar 2008
Not sure if you wanted worksheet functions or VBA to do this and if you want
VBA, if you need further instructions and also how you want to initiate the
running of the macros to change the fonts. The following two activate on
changes to cells. (You can only use one of them. See the comments following
the sub name for what activates them).

Right click on the tab sheet name and select View Code and copy one of the
macros into the VAB editor. To close the VBA editor, click on the X with the
red background top right of VBA editor window.

First Option:-
Private Sub Worksheet_Change(ByVal Target As Range)
'Changes the colors of Cell A1 based on a change to the cell A1
Select Case Target
Case Range("A1")
With Target
.Characters(1, Cells(2, "A")).Font.Color = vbRed
.Characters(5, Cells(3, "A")).Font.Color = vbBlue
End With
Case Range("B1")
'Another option here
Case Range("C1")
'Another option here
End Select
End Sub


Second option:-
Private Sub Worksheet_Change(ByVal Target As Range)
'Changes the colors based on a change to either A2 or A3
Select Case Target
Case Range("A2"), Range("A3")
With Range("A1")
.Characters(1, Cells(2, "A")).Font.Color = vbRed
.Characters(5, Cells(3, "A")).Font.Color = vbBlue
End With

Case Range("A4"), Range("A5")
'Further options here if required

End Select

End Sub

--
Regards,

OssieMac


"kimbobo" wrote:

> Hi All,
>
> Does anyone know how to change the color of characters in a cell based
> of a cell reference.
>
> For example, cell A1 = "||||||||||" (contains 10 "|") I want the first
> 4 "|" to be Red and the second 6 to Blue. Based of cells A2 = 4 and A3
> = 6.
>
> Any ideas?
>
> Thanks!!
>
> -Kim
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change background color of cell based on vlookup in cell Antney Microsoft Excel Misc 1 19th Oct 2009 10:55 PM
Change Text Color in one cell based upon entry in referenced cell Tee Microsoft Excel Misc 3 12th Sep 2008 10:07 PM
Change color of characters in a cell based of a cell reference kimbobo Microsoft Excel Discussion 2 22nd Mar 2008 01:57 AM
How do I change cell color based upon data range within the cell? =?Utf-8?B?Q2hyaXMgU2FuZGVycw==?= Microsoft Excel Worksheet Functions 1 6th Mar 2006 08:59 PM
Cell compare and based on the value change the cell background color pftiv Microsoft Excel Worksheet Functions 2 15th Jan 2004 04:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:39 PM.