isnumeric() and hyphen
John,
IsNumeric will anything that looks like a number and is somewhat easy to
fool.
Depending on what you want to allow/deny, maybe Val, or CDbl and trap the
error will work.
Or monitor the key strokes with the KeyDown/keyPress events.
Alternatively, give the user an input box restricted to numbers:
Const NumbersOnly As Long = 1
Application.InputBox(,,,,,,,NumbersOnly )
NickHK
"John Smith" wrote in message
...
But if I mistakenly type "100-", isnumeric() doesn't sense the
error. It only senses the error after I punch another key,
alphabets or numbers. Don't know what isnumeric() was waiting for.
Dave Peterson wrote:
So that you can enter negative numbers???
John Smith wrote:
Why does isnumeric() treat hyphen differently than it does other
letters? In the following code, the first hyphen does not trigger
the msgbox, though alphabets do. So is the second hyphen.
sub textbox1_change()
if NOT isnumeric(textbox1.value) then
Msgbox ("You must enter a number.")
end if
end sub
|