View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Spongie Spongie is offline
external usenet poster
 
Posts: 4
Default Changing font style and color using VBA

I have been trying (unsuccessfully!) to write some code to change the font
style and color based on specific criteria.

I have a spreadsheet with input cells in columns A & B and a formula in
column C to determine the % variance between the 2. What I want to do is in
column D return a symbol based on a RAG status (Red, Amber, Green). I can't
do this using a formula as the Red and Green symbols are Wingdings and the
Amber symbol uses Wingdings 3.

So if A1=40 and B1=45 the variance is 11% (as shown in C1)and I'd like this
to return a particular symbol (Amber triangle), which I believe is:
Value = ""
Font Name = Wingdings 3
Font Color = RGB(255,192,0)

But I'm struggling with the actual code....please don't laugh at my pathetic
attempts (completely self-taught) but this is what I wrote....

Private Sub Worksheet_Change(ByVal Target As Range)

If Range("G6") <= 0.1 Then
With Range("H6")
..Value = "l"
..Font.Name = "Wingdings"
..Font.Color = RGB(0, 0, 255)
End With

ElseIf Range("G6") <= 0.2 Then
With Range("H6")
..Value = ""
..Font.Name = "Wingdings 3"
..Font.Color = RGB(255, 192, 0)
End With

ElseIf Range("G6") 0.2 Then
With Range("H6")
..Value = "«"
..Font.Name = "Wingdings"
..Font.Color = RGB(255, 0, 0)
End With

End If

It inputs the correct symbol but then Excel completely freezes...what am I
doing wrong??

Any help greatly appreciated!