VBA Function - IsNumeric Allows some Special Characters

NSN_VBA

New Member
Joined
Aug 3, 2018
Messages
7
Hi,

1st time on here so bear with me. I have written the following code, to ensure only numerical values are entered in a VBA form input box;

Private Sub OperatorNumber_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)

If Not (IsNumeric(OperatorNumber.Value) = True) Then
Call OperatorNumberShowError("Numbers Only!")
Cancel = True
Else
End If
End Sub

This works fine, but what I have found is that certain special characters, such as: "+" can be entered which doesn't work for what I am trying to achieve.

I would like to write a function, that I can refer to using the following code, that will allow only numbers and decimals, but exclude all other characters, this is where I am struggling, please is someone able to help?

Else
If Not (IsOnlyNumbersAndDecimals(OperatorNumber.Value) = False) Then
Call OperatorNumberShowError("No Special Characters!")
Cancel = True
End If

Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi & welcome to MrExcel.
Have a look here & see if it helps
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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