This code will color any cell you enter data in, if you empty data it will un-color the cell background. It does not work on any cell with data pre-loaded!
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range)
Dim rng As Range
'Make all calls with data entered colored.
'Makes cells with data removed un-colored.
'Load from ThisWorkBook Module.
With Application
.EnableEvents = False
For Each rng In Source
If rng.Value<> "" Then
rng.Interior.ColorIndex = 6
Else
rng.Interior.ColorIndex = xlNone
End If
Next
.EnableEvents = True
End With
End Sub
You can also use "Conditional Formatting." Block the range you want it to work on, then use "Cell Value Is" "Not Equal To" enter this in formula box: =""
This code does the same thing only by different code. Here you can set the range it works on and set different case conditions. You can set as many colors or conditions as you wish, just by adding additional case statements to the chain.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myColor As Integer
If Not Intersect(Target, Range("A1:AA10")) Is Nothing Then
Select Case Target
Case Is<> ""
myColor = 6
Case Is = ""
myColor = 0
Case Else
'Whatever
End Select
Target.Interior.ColorIndex = myColor
End If
End Sub
Hope this helps. JSW
This message was edited by Joe Was on 2002-09-25 14:12