Formatting in excel 2003

Closed
POMEGRANATE Posts 1 Registration date Sunday October 7, 2012 Status Member Last seen October 7, 2012 - Oct 7, 2012 at 05:50 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Oct 8, 2012 at 10:37 AM
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.
Related:

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Oct 8, 2012 at 10:37 AM
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
0