sNumeric excepting + or - signs

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
647
Office Version
  1. 2016
Platform
  1. Windows
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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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).
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,479
Members
448,967
Latest member
visheshkotha

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