VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub ' this stops code error if more than one cell is changed at once
If Not Application.Intersect(Target, Me.Range("D2:D2002")) Is Nothing Then ' indicates the Target range
If Left(Target, 4) = "STW " Or Left(Target, 5) = "PSTW " Or Left(Target, 4) = "TTW " Then
Exit Sub
Else
MsgBox ("ALL SHIFT MUST HAVE A SPACE BETWEEN STW,PSTW,TTW AND THE HOURS")
Target = ""
End If
End If
End Sub
Using the code above I able to alert the user if STW, PSTW, and TTW are not followed by Space however when I add to Clear the Target value
VBA Code:
Target = ""