Hello everyone I want to accomplish the following with this vba:
in Range (D2:D2002) users will be typing STW, PSTW, TTW followed by space and then start and end time without colons. ex. "STW 900-1730" , "PSTW 2100-2130" or "TTW 430-1300"
what I need the code to do is for all single digit start times from 1-9 to add a 0 in front.
ex.
"STW 900-1730" should change automatically to "STW 0900-1730"
"TTW 430-1300" to "TTW 0430-1300"
"PSTW 700-800" to "PSTW 0700-800"
it would be nice if the single digits after "-" to add 0 in front if not to complicated so if "PSTW 700-800" becomes "PSTW 0700-0800" that would be wonderful if not "PSTW 0700-800" would be good aswell.
any help is greatly appreciated
I do currently have the below code to check for space between STW, PSTW, and TTW just like to add the above feature.
in Range (D2:D2002) users will be typing STW, PSTW, TTW followed by space and then start and end time without colons. ex. "STW 900-1730" , "PSTW 2100-2130" or "TTW 430-1300"
what I need the code to do is for all single digit start times from 1-9 to add a 0 in front.
ex.
"STW 900-1730" should change automatically to "STW 0900-1730"
"TTW 430-1300" to "TTW 0430-1300"
"PSTW 700-800" to "PSTW 0700-800"
it would be nice if the single digits after "-" to add 0 in front if not to complicated so if "PSTW 700-800" becomes "PSTW 0700-0800" that would be wonderful if not "PSTW 0700-800" would be good aswell.
any help is greatly appreciated
I do currently have the below code to check for space between STW, PSTW, and TTW just like to add the above feature.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Application.Intersect(Target, Me.Range("D2:D2002")) Is Nothing Then
If Left(Target, 4) = "STW " Or Left(Target, 5) = "PSTW " Or Left(Target, 4) = "TTW " Then
Exit Sub
Else
MsgBox ("ALL SHIFT MUST INCLUDE STW, PSTW, TTW FOLLOWED BY A SPACE")
Application.EnableEvents = False
Target = ""
Application.EnableEvents = True
Target.Select
End If
End If
End Sub