Hi,
I have below simple VBA code where if the value in CE1 is 1 then highlight cell D5 in White otherwise in Red. When i run the code it highlights in red when the value is other then 1 but it doesnt highlight it when CE1 is equal to 1. Can someone please help? Thanks
Update - Below did the trick
I have below simple VBA code where if the value in CE1 is 1 then highlight cell D5 in White otherwise in Red. When i run the code it highlights in red when the value is other then 1 but it doesnt highlight it when CE1 is equal to 1. Can someone please help? Thanks
Code:
Sub ColorD5()
Dim r1 As Range, r2 As Range
Set r1 = Range("CE1")
Set r2 = Range("D5")
If r1.Value = 1 Then
r2.Interior.Color = vbWhite
Else
r2.Interior.Color = vbRed
End If
End Sub
Update - Below did the trick
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("CE1")
Dim r1 As Range, r2 As Range
Set r1 = Range("CE1")
Set r2 = Range("D5")
If r1.Value = 1 Then
r2.Interior.Color = vbWhite
Else
r2.Interior.Color = vbRed
End If
End Sub
Last edited: