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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi & welcome to MrExcel.
Have a look here & see if it helps
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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