Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
'Which cells do you want to change colors?
Set MyRange = Range("A2:A10")
If Intersect(MyRange, Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
With Target.Interior
If .ColorIndex = 3 Then
.ColorIndex = 4 'green
Else
.ColorIndex = 3 'Red
End If
End With
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
Dim SwitchCell As Boolean
'Which cell contains True/False?
SwitchCell = Range("A1").Value
'If turned off, don't run
If Not (SwitchCell) Then Exit Sub
'Which cells do you want to change colors?
Set MyRange = Range("A2:A10")
If Intersect(MyRange, Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
With Target.Interior
If .ColorIndex = 3 Then
.ColorIndex = 4 'green
Else
.ColorIndex = 3 'Red
End If
End With
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Calculate()
Dim MyRange As Range
Dim SwitchCell As Boolean
'Which cell contains True/False?
SwitchCell = Range("A1").Value
'If turned off, don't run
If Not (SwitchCell) Then Exit Sub
'Which cells do you want to change colors?
Set MyRange = Range("A2:A10")
Application.EnableEvents = False
'Will now look through every cell in the range
For Each c In MyRange
With c.Interior
If .ColorIndex = 3 Then
.ColorIndex = 4 'green
Else
.ColorIndex = 3 'Red
End If
End With
Next c
Application.EnableEvents = True
End Sub