Custom Number Format

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi,

How could I write an after event code for the text box "txttime" so that when the user leaves the text box after writing four digit numbers the text box would display the values as follows;

For example when the user writes 1234, the numbers would be displayed as 12:34.

Any help on this would be kindly appreciated.

Thanks in advance.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Perhaps this, adjusting textbox name accordingly

Code:
Private Sub TextBox1_LostFocus()
Me.TextBox1.Value = Format(Me.TextBox1.Value, "00\:00")
End Sub
 
Upvote 0
Thanks for the help.

In a situation if the user writes the time for example 06:01 as 61 and leaves the textbox it displays the time as 00:61.

How could I avoid this or create a message saying that the user have to enter time in the 24 hour format as 00:00.

I hope I've made my question clear.

Any help on this would be kindly appreciated.
 
Upvote 0
have you thought of using data validation, under input message you can put in instructions, so whenever someone mouse's over or tabs into that square a little pop up shows with instructions
 
Upvote 0
Perhaps

Code:
If Instr(1, Me.Textbox1.Value, ":") = 0 Then
    Me.TextBox1.Value = Format(Me.TextBox1.Value, "00\:00")
End If
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top