sNumeric excepting + or - signs

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
625
HiI
I am using the below code attached to a camand button on an excel 2007 userform

I wanted only whole number to be excepted, but this code will allow the + or - sign at the end of the number. How can I correct this?

If IsNumeric(Me.txtbox1.Value) Then

ws.Cells(iRow, 1).Value = Me.txtbox1.Value
Else
MsgBox "Please enter a numeric value"
Me.txtbox1.Value = ""
Me.txtbox1SetFocus
Exit Sub

Thanks
L
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,792
Office Version
  1. 2019
Platform
  1. Windows
Is your intention to disallow negative numbers? And do you care what the value in the textbox looks like? For instance, if 15+ is entered and is interpreted by Excel as 15, or 15- is entered and is interpreted by Excel as 15- then there should be no problem ... in other words, how should negatives be treated and what are allowed vs. disallowed number formats (personally, I would allow any valid number format, though I might "re-format" to a consistent display format after entry).

(Is this a Canadian thing to put signs after the numbers? We put them in front here in the old US of A).
 

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
625
HI
No normally we do not put plus + after the number only - in front if it is negative.

The number's I will be inputting will alway be positive as they repersent a product # of 12 digits. I just by mistake hit the + instead of the 6 and was superized that it was excepted.

Thanks
L
 

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,792
Office Version
  1. 2019
Platform
  1. Windows
Most ordinary representations of numbers will pass the "numeric" test. For instance, any of the following

5000
+5000
5,000
(5,000)
$5,000

Perhaps in your case if you want a strict validation you could validate each character in the string as numeric, one by one.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,207
Messages
5,594,840
Members
413,944
Latest member
3xc3ln00b

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
Top