Check userform values

robfo0

Active Member
Joined
Feb 19, 2002
Messages
281
Hi,

Is there a quick code that i can use to make sure that a value in a text box on my userform is a number (0-9), and if its not, give a message or something?

Thanks :)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try the following code:

If Application.WorksheetFunction.And(textbox1.Value >= 0, textbox1.Value <= 9) = False Then MsgBox "Incorrect value"

Replace textbox1 with the name of your textbox.
 
Upvote 0
Al, thanks for the quick response, but actually I worded my question wrong. I want the value to be a number, but it may have multiple digits...so it could be 12345 etc. I'm just trying to keep everying except numbers out of the field. How would i do that? :) thanks Al
 
Upvote 0
If Not Application.WorksheetFunction.IsNumber(textbox1.Value) _
Then MsgBox "Make it a number please. Merci."


_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
This message was edited by NateO on 2002-04-02 15:41
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,457
Members
448,898
Latest member
drewmorgan128

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