vba userform textbox numeric only

jam1531

New Member
Joined
Jan 5, 2015
Messages
29
Hello,

Looking for the code to check a userform textbox to see if anything in it contains anything other than numbers. Basically textbox1 takes the input and finds the numbers, however if someone accidently inserts letter or special character instead of a number it messes my other code up. I would like to add one if in the below code that ensures that textbox1 only contains numbers and if not gives a message box saying "please ensure values are numeric only" and then exits sub. Any help appreciated.

Code:
    If DeleteTool.TextBox1 = "" Then        'Appears if there is no Item input
            MsgBox ("Please insert item number(s)")
                GoTo finish
    End If
 
Last edited:
I think you might find this interesting. Below is a modification of your code that, one, uses the Like operator to eliminate the For..Next loop, two, restructures your to If..Then blocks into an If..ElseIf..Else block (both of the above in the Click event) and modified your If..Then logical expression in the KeyPress event.



This was the idea: "ElseIf TextBox1 Like" * [! 0-9] * "Then", but at that moment I came up with the loop. I appreciate the comments.
 
Upvote 0

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.

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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