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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Anthony47

Well-known Member
Joined
Mar 29, 2006
Messages
1,969
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,119,192
Messages
5,576,598
Members
412,737
Latest member
mjo1234
Top