Time in a userform textbox

Diving_Dan

Board Regular
Joined
Oct 20, 2019
Messages
149
So I have scoured google looking for the answer but I can't find exactly what I'm looking for.

I've got a userform to input data onto a worksheet. One of the textboxes is called textTimeAuthorised and the time gets put into this textbox in 24hr format. what I am trying to achieve is after the hours have been put in it automatically adds the colon for the time rather than having to manually input it.

Is this easily possible?

Thanks in advance

Dan
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Anthony47

Well-known Member
Joined
Mar 29, 2006
Messages
1,970
Try using the following TextBox_Change macro:
VBA Code:
Private Sub textTimeAuthorised_Change()
Dim cTxt As String
'
cTxt = Me.textTimeAuthorised.Text
If Len(cTxt) = 2 And Right(cTxt, 1) <> ":" Then
    Me.textTimeAuthorised = cTxt & ":"
End If
End Sub
Bye
 

Watch MrExcel Video

Forum statistics

Threads
1,122,355
Messages
5,595,676
Members
414,009
Latest member
SNesbyCarr

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
Top