Verify Date is entered into Text Box

MattOCUSA

Board Regular
Joined
Jan 12, 2007
Messages
231
On my user form, I have a text box that is for date entries only. Is there a way to evaluate if my user did infact enter a date format number into the text box? I want to be able to let them enter these dates freehand.

Thank You,
Matt
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
yah, isdate

Code:
Private Sub CommandButton1_Click()
Dim datee As String

datee = UserForm1.TextBox1.Value
If IsDate(datee) = False Then MsgBox "Dude, what are you doing?!"

End Sub
 
Upvote 0
Cool! OK, is there a function like IsDate for "IsNumber" to be used with the text box data (to check for a number instead of a date in another situation)? I thought that since the value was "text" in a text box that I couldn't do checks on them like that?

Thanks Guys!!
Matt
 
Upvote 0
Try IsNumeric, place this in the TextBox_Exit event. Change the code to use IsDate when needed. This way if an incorrect entry is made the user is immediately alerted.

Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.TextBox1
        If Not IsNumeric(.Value) Then
            .Value = ""
            .SetFocus
            MsgBox "Numbers only", vbCritical, "Input error:"
        End If
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,266
Members
448,558
Latest member
aivin

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