Formatting TextBoxes in Userform

AndrewGKenneth

Board Regular
Joined
Aug 6, 2018
Messages
59
Hi there,

I would like to format a textbox in my userform, so that only the correct format can be inputted. I would like the format to be the following dd/mm/yyyy 00:00:00 so the user has to enter both the date and time otherwise the box will error. Could anymore please show me the code to do this?

Thanks so much,
Andrew
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi there,

I would like to format a textbox in my userform, so that only the correct format can be inputted. I would like the format to be the following dd/mm/yyyy 00:00:00 so the user has to enter both the date and time otherwise the box will error. Could anymore please show me the code to do this?

Thanks so much,
Andrew

Something like this :
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If Len(TextBox1.Text) > 0 Then
        If Not IsDate(TextBox1.Text) Or Not TextBox1.Text Like "##/##/#### ##:##:##" Then
            Cancel = True
            MsgBox "Incorrect format inputted!" & vbCrLf & vbCrLf & _
            "The correct format should be :" & vbCrLf & "dd/mm/yyyy 00:00:00", vbCritical
        End If
    End If
End Sub
 
Upvote 0
Thanks Jaafar, much appreciated. I will give this a go tomorrow when I am back in the office and let you know how I get on!
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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