Formatting in excel 2003

[Closed]
Report
Posts
1
Registration date
Sunday October 7, 2012
Status
Member
Last seen
October 7, 2012
-
Posts
2819
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
October 25, 2021
-
Hello,

I would like to format cells to change to red when I type in R, blue when I type B, yellow for Y and green for G. I know that I can't use conditional formatting and that I need to use a macro but have no idea what to use or how to run it once I've written it in the VBA. Any ideas?

Thanks.

1 reply

Posts
2819
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
October 25, 2021
487
Hi Pomegranate,

Here you go:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "R" Then Target.Interior.ColorIndex = 3
If Target.Value = "B" Then Target.Interior.ColorIndex = 5
If Target.Value = "Y" Then Target.Interior.ColorIndex = 6
If Target.Value = "G" Then Target.Interior.ColorIndex = 10
End Sub


How to implement the code?:
Right click on the sheets tab, select view code and paste the code.

Best regards,
Trowa