Dark0Prince
Active Member
- Joined
- Feb 17, 2016
- Messages
- 433
I can't get this code to reformat the time to hh:mm and keep the numbers there. it just clears the number and reformats the field.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Selection.Count > 1 Then
Exit Sub
End If
If Not Intersect(Range("C3:N33"), Target) Is Nothing Then
TLlen = Len(Target)
If TLen = 1 Then
TimeV = TimeValue(Target & ":00")
ElseIf TLen = 2 Then
TimeV = TimeValue(Target & ":00")
ElseIf TLen = 3 Then
TimeV = TimeValue(Left(Target, 1) & ":" & Right(Target, 2))
ElseIf TLen = 4 Then
TimeV = TimeValue(Left(Target, 2) & ":" & Right(Target, 2))
ElseIf TLen > 4 Then
'do nothing
End If
Target.NumberFormat = "HH:MM" 'am/pm if you want am and pm
Application.EnableEvents = False
Target = TimeV
Application.EnableEvents = True
End If
End Sub