Time formats in A form AND in a worksheet

  • Thread starter Thread starter Corey
  • Start date Start date
C

Corey

I am using a form to input data into a sheet and am having diffculty trying to get the time format
correct.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub TextBox24_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox24.Value = Format(TextBox24.Value, "hh:mm AM/PM")
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The user will enter a time in a 24hr format (eg. 0630 or 1530), but i cannot seem to get the textbox
to change the 1530 into 3:30PM. I keep getting 12:00PM instead....

OR is there a form designed similar to the frmCalendar to select a tim in 15min increments from a
clock face or similar ?

Corey....
 
Hi Corey,

Try this:-

Dim strTemp as String

strTemp = Left(TextBox24.Value, 2) & ":" & Right(TextBox24.Value, 2)

TextBox24.Value = Format(strTemp, "hh:mm AM/PM")

Regards,

OssieMac
 
Try this:-
Dim strTemp as String

strTemp = Left(TextBox24.Value, 2) & ":" & Right(TextBox24.Value, 2)

TextBox24.Value = Format(strTemp, "hh:mm AM/PM")

You can also do it this way...

TextBox24.Value = Format(Format(TextBox24.Value, "@@:@@"), "hh:mm AM/PM")

Rick
 
Thanks Rick perfect !!


Rick Rothstein (MVP - VB) said:
Try this:-

Dim strTemp as String

strTemp = Left(TextBox24.Value, 2) & ":" & Right(TextBox24.Value, 2)

TextBox24.Value = Format(strTemp, "hh:mm AM/PM")

You can also do it this way...

TextBox24.Value = Format(Format(TextBox24.Value, "@@:@@"), "hh:mm AM/PM")

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top