eddyrcabrera79
Member
Hi,
I’m working with a Userform that transfer information into an excel sheet. One of the Textbox is called (Start Time). When I click on it, it will ask me to enter the time. This is the help I require.
1 – How can I make the colon ) symbol to populate by itself. Ex: I would like to type 400 and it will populate 4:00
2 – I will also have to type if it is AM or PM. I would like to type the time: Ex – 400pm and I would like to be populated like this 4:00 AM (There will have to be a space after the time and the am or pm will have to change to UPPERCASE
Please see below the code I’m using at the moment
Regards,
I’m working with a Userform that transfer information into an excel sheet. One of the Textbox is called (Start Time). When I click on it, it will ask me to enter the time. This is the help I require.
1 – How can I make the colon ) symbol to populate by itself. Ex: I would like to type 400 and it will populate 4:00
2 – I will also have to type if it is AM or PM. I would like to type the time: Ex – 400pm and I would like to be populated like this 4:00 AM (There will have to be a space after the time and the am or pm will have to change to UPPERCASE
Please see below the code I’m using at the moment
Code:
Private Sub StartTimeTextBox_Enter()
Dim MyInput As Variant
MyInput = Application.InputBox("hh:mm AM/PM (12 Hour Format)", "Please enter the Start time")
MyVal = MyInput
If MyInput = Format(MyVal, "hh:mm AM/PM") And _
Mid(MyInput, 4, 2) <= 59 And _
Mid(MyInput, 4, 2) >= 0 And _
Left(MyInput, 2) >= 1 And _
Left(MyInput, 2) <= 12 Then
StartTimeTextBox.Value = MyInput
ElseIf _
Mid(MyInput, 4, 2) <= 59 And _
Mid(MyInput, 4, 2) >= 0 And _
Left(MyInput, 1) >= 1 And _
Left(MyInput, 1) <= 9 Then
StartTimeTextBox.Value = MyInput
Else
MsgBox "Time Format is incorrect" & vbNewLine & "Please ensure it is in hh:mm AM/PM", vbCritical, ""
End If
End Sub
Regards,