Input mask for active cell
I am attempting to set up an input mask for the active cell such that the
time can be entered as 3 or 4 digits without the full colon.(815 for 08:15
AM)
In the sample code below, I never get to the numberformat property and the
code sems to be recursively called from itself. I've tried both the
Calculate and the Change events. What's my best solution?
Thanks!
Lee
Private Sub Worksheet_Some_event(ByVal Target As Range
Dim InTime As String
Dim Apostrophe As String
Apostrophe = ""
If Len(Target) = 4 Then ' Allow 815 instead of 0815
InTime = Apostrophe & Left(Target.Value, 2) & ":" & Right(Target.Value, 2) &
Apostrophe
Else: InTime = Apostrophe & "0" & Left(Target.Value, 1) & ":" &
Right(Target.Value, 2) & Apostrophe
End If
ActiveCell.Value = InTime
ActiveCell.NumberFormat = "hh:mm A"
End Sub
|