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 last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi & welcome to MrExcel.
Have a look here & see if it helps
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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