ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Entering military time into a userform (https://www.excelbanter.com/excel-programming/325319-entering-military-time-into-userform.html)

WillRn

Entering military time into a userform
 
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

JulieD

Entering military time into a userform
 
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

"WillRn" wrote in message
...
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




WillRn

Entering military time into a userform
 
Thank You Julie! It was just what I needed.

Much Thanks,

WillRn

"JulieD" wrote:

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

"WillRn" wrote in message
...
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





JulieD

Entering military time into a userform
 
you're welcome and thanks for the feedback

"WillRn" wrote in message
...
Thank You Julie! It was just what I needed.

Much Thanks,

WillRn

"JulieD" wrote:

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

"WillRn" wrote in message
...
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








All times are GMT +1. The time now is 10:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com