bdouglas1011
New Member
- Joined
- Jul 28, 2014
- Messages
- 38
I have this code that allows the user to enter the time as 1520 not 15:20.... saves on time.... but if you or someone not used to the sheet uses a ":" it messes up the cell.
Can this be altered to include both versions. Either use : or dont.
Can this be altered to include both versions. Either use : or dont.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim EndTime As Range
Dim SBlank As String
SBlank = """" & """"
Set EndTime = Range("B10:B47")
Application.EnableEvents = True
If Target.Column <> 2 Or Target.Count > 1 Or Target.row < 10 Or Target.row > 47 Then Exit Sub
If Not Application.Intersect(EndTime, Range(Target.Address)) Is Nothing Then
If Target.Value = "" Then
Target.Offset(1, -1).Value = ""
GoTo 99
End If
If Intersect(Target, Range("B10:B47")) Is Nothing Then Exit Sub
Dim xHour As String
Dim xMinute As String
Dim xWord As String
Application.EnableEvents = False
xWord = Format(Target.Value, "0000")
xHour = Left(xWord, 2)
xMinute = Right(xWord, 2)
On Error Resume Next
Target.Value = TimeValue(xHour & ":" & xMinute)
On Error Resume Next
Application.EnableEvents = True
If TimeValue(Format(Target.Value, "hh:mm")) <> "12:00:00 AM" Then
Target.Offset(1, -1).Value = "=IF(ISBLANK(B" & Target.row & ")," & SBlank & ",B" & Target.row & ")"
End If
End If
99:
End Sub