I have a listbox from which to choose font color for editing, linked to another cell. This code points to that linked cell to find the color choice and then specifies the font should be that color. It only works sometimes and I cannot figure out why. I put in the msgBox to track the variable. The message box comes up, but the variable value does not. So clearly the variable is not being set properly. Any ideas?
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:z300"
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Dim colorchoice As String
Dim color As Integer
'Application.ScreenUpdating = False
Sheets(4).Activate
colorchoice = Range("b1").Value
If colorchoice = RED Then
color = 3
ElseIf colorchoice = BLUE Then
color = 5
ElseIf colorchoice = "GREEN" Then
color = 4
Else: color = 17
End If
Sheets(1).Activate
'Application.ScreenUpdating = True
With Target
.Font.ColorIndex = color
MsgBox "color is" & colorchoice
End With
End If
End Sub
Bookmarks