Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm not sure checking the numeracy of an entry is as critical at the
spreadsheet level as it is a the programming level. If you enter a non-number in a cell, any formulas relying on the entry to be a number will provide instant feedback to the user so that he/she will know that something must be corrected. However, within a program, the reaction to a bad entry is usually hidden from the user and so the program must implement code to guard against bad entries. Unfortunately, IsNumeric is badly named and many, many people looking for a "normal" shaped number use it because the name seems to indicate that is what it exists for. You are right, IsNumeric is really a CanBeNumeric function and pretty much exists for use in the Cxxx function (CInt, CLng, CDbl, etc.). I can just hear you saying, "Wait a minute, what do you mean by that statement?" Well, believe it or not, VB/VBA is perfectly happy with something like CDbl("$(2,,e12)$"); for example MsgBox CDbl("$(2,,e12)$") will happily display a MessageBox with -2000000000000 in it (the $ signs and commas are flushed, the parentheses are interpreted as negating the value and the 'e' is the normal way to show a power of 10). If the entry were smaller, such as like "$(2,,e2)$", both CInt and CLng would be happy with it too. Rick "Tim Zych" <tzych@NOSp@mE@RTHLINKDOTNET wrote in message ... Good points Rick..interesting walkthrough. It seems safer to use Excel's IsNumber function (Excel.WorksheetFunction.IsNumber) or even SpecialCells than IsNumeric. I haven't played around with IsNumber it enough to know if it let's non-numeric characters "pass the test" like IsNumeric does, but it certainly seems to evaluate better what it's function name suggests. Perhaps "IsNumeric" should be renamed "CanBeNumeric". -- Tim Zych SF, CA "Rick Rothstein (MVP - VB)" wrote in message ... If Len(c.Value) = 10 And IsNumeric(c.Value) = True Then The above statement is from your posted code. The IsNumeric function is not one of the best ways to "proof" an entry for being all digits (or even a floating point value for that matter). For example, put "$(2,,e12)$" (without the quote marks) in one of the cells being tested by your code and the logical statement for the If function will return True when it gets to that cell. I would perform the test this way... |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Finding NEXT to last, non zero numeric value in a row | Excel Worksheet Functions | |||
TO DELETE ONLY NUMERIC VALUES IN A CHARACTER AND NUMERIC CELL IN | Excel Discussion (Misc queries) | |||
finding only cells with a numeric value | Excel Discussion (Misc queries) | |||
Return Numeric Labels that have different Numeric Values | Excel Worksheet Functions | |||
Finding the mode (alpha numeric) | Excel Discussion (Misc queries) |