VBA IsNumeric is going to WILD

Please explain why the code below behaves randomly

The line of code below returns TRUEwhen it should have returnFALSE

?Isnumeric("555-")

Also

?Isnumeric("555-"/2) returns TRUE

Please explain this random behavior IsNumeric?

+4
source share
3 answers

Although this is a little esoteric, the final minus is a valid number format, which is sometimes used in accounting packages. Probably now it is not used so much. It indicates a negative number, for example. 555- - -555. Your second example works, because -555 (or 555-) can be divided by 2, i.e. -227.5 (or 227.5 -).

Excel, :

enter image description here

, :

#,##0;#,##0-

blog-post.

+7

Microsoft:

IsNumeric True, Expression , , , , , , SByte, Short, Single, UInteger, ULong UShort , . True, Char , .

IsNumeric False, Date Object . IsNumeric False, Char , .

+3

He appears to interpret “555-” as -555. After checking IsNumeric, you can detect this situation as follows:

Cstr(CLng("555-")) = "555-"
+2
source

Source: https://habr.com/ru/post/1652980/


All Articles