Restrict Input Value In Userform Text Box

spycein

Board Regular
Joined
Mar 8, 2014
Messages
135
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

Is there any vba formula to restrict data input in a userform textbox.

I need to enter "MM/DD/YY" format value only, otherwise textbox will not accept the value.

Let me elaborate more, Numbers 01 to 12 should be allowed followed by "/" then numbers 01 to 31 should be allowed followed by "/" then any two digit numbers should be allowed to enter in text box otherwise a message should appear stating that "Invalid Date Format" .

Hope You guys understand my query.

Waiting for your suggestions.

Thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try something like this...

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] TextBox1_Exit([COLOR=darkblue]ByVal[/COLOR] Cancel [COLOR=darkblue]As[/COLOR] MSForms.ReturnBoolean)
    [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] IsDate(TextBox1.Value) [COLOR=darkblue]Then[/COLOR]
        MsgBox "Plaese enter a date. ", vbExclamation, "Invalid Date Entry"
        Cancel = [COLOR=darkblue]True[/COLOR]
    [COLOR=darkblue]Else[/COLOR]
        TextBox1.Value = Format(TextBox1.Value, "mm/dd/yy")
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
End [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0
Thanks Alpha Frog..... Work like a charm...
Thank you so much...:)
 
Upvote 0

Forum statistics

Threads
1,213,515
Messages
6,114,080
Members
448,548
Latest member
harryls

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