Entering military time into a userform

G

Guest

I have a textbox on a userform for a military time (24 hour clock). The
trouble is that I can't seem to get any format codes to work.

I just want the user to be able to input a 4 digit time and have the input
display in the textbox as a 24 hour short time.

For example: User inputs 1345 and then textbox displays 13:45. The value
then postd to the spreadsheet would be 13:45.

I know this is probably simple, but I can't seem to get anything to work.

WillRn
 
J

JulieD

Hi WillRn

Something along the lines of

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Hr = Int(Me.TextBox1 / 100)
Min = Me.TextBox1 Mod 100
Sec = 0
Me.TextBox1 = Format(TimeSerial(Hr, Min, Sec), "hh:mm")
Range("A1").Value = TimeSerial(Hr, Min, Sec)
Range("a1").NumberFormat = "hh:mm"
End sub

Cheers
JulieD
 

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

Top