I have a shift schedule setup. Each half hour is marked by a single character, either an l or t.
I am trying to use VBA to change the cell pattern/colors. If a user inputs more than one character the code will change the cell formatting. I would also like for it to prompt the user that they have entered invalid characters, not sure where the best spot for this would be.
Here is my code:
Note: "MondaySchedule" refers to a named range of "C5:S10"
Absolutely nothing happens. I don't know what I am missing. Any help would be appreciated.
I am trying to use VBA to change the cell pattern/colors. If a user inputs more than one character the code will change the cell formatting. I would also like for it to prompt the user that they have entered invalid characters, not sure where the best spot for this would be.
Here is my code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim C As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("MondaySchedule")) Is Nothing Then
For Each C In Target
If Not (Target = 0) Then
If Len(Trim(C)) > 1 Then
With C.Interior
.Color = RGB(0, 0, 255)
.Pattern = xlPatternHorizontal
.PatternColor = RGB(0, 255, 0)
End With
End If
' MsgBox "Multiple Characters in Cell!"
' Exit Sub
End If
Next cell
End If
ws_exit:
Application.EnableEvents = True
End Sub
Note: "MondaySchedule" refers to a named range of "C5:S10"
Absolutely nothing happens. I don't know what I am missing. Any help would be appreciated.