LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default finding only numeric values in a worksheet using vb.net?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding NEXT to last, non zero numeric value in a row gergster Excel Worksheet Functions 3 April 16th 10 01:58 PM
TO DELETE ONLY NUMERIC VALUES IN A CHARACTER AND NUMERIC CELL IN ramesh k. goyal - abohar[_2_] Excel Discussion (Misc queries) 1 October 28th 09 06:50 AM
finding only cells with a numeric value Eelinla Excel Discussion (Misc queries) 3 April 21st 07 07:01 PM
Return Numeric Labels that have different Numeric Values Sam via OfficeKB.com Excel Worksheet Functions 8 December 3rd 06 02:06 AM
Finding the mode (alpha numeric) Jamesy Excel Discussion (Misc queries) 3 July 26th 05 03:12 PM


All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright Đ2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"