Creating a Formula to Format Column automatically?

G

Gord Dibben

You can have 4 conditions.

1. The default

2,3,4 other conditions.

More than that would require Code, most likely Event code.

Example....

Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Variant
Set vRngInput = Intersect(Target, Range("D:D"))
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = "A": Num = 10 'green
Case Is = "B": Num = 1 'black
Case Is = "C": Num = 5 'blue
Case Is = "D": Num = 7 'magenta
Case Is = "E": Num = 46 'orange
Case Is = "F": Num = 3 'red
End Select
'Apply the color
rng.Interior.ColorIndex = Num
Next rng
endit:
Application.EnableEvents = True
End Sub

For more on Event code see..

http://www.cpearson.com/excel/events.htm
http://www.mvps.org/dmcritchie/excel/event.htm

Gord Dibben Excel MVP
 
Top