Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a 10 character number string. I need a test to confirm that
there are no non-numeric characters in this string. Thanks Excel97 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Look at this example: If isnumeric(MyString) then 'numeric string else 'whatever endif Regards, Per On 22 Jan., 05:59, Fan924 wrote: I have a 10 character number string. I need a test to confirm that there are no non-numeric characters in this string. Thanks Excel97 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Consider this previous posting of mine...
I usually try and steer people away from using IsNumeric to "proof" supposedly numeric text. Consider this (also see note below): ReturnValue = IsNumeric("($1,23,,3.4,,,5,,E67$)") Most people would not expect THAT to return True. IsNumeric has some "flaws" in what it considers a proper number and what most programmers are looking for. I had a short tip published by Pinnacle Publishing in their Visual Basic Developer magazine that covered some of these flaws. Originally, the tip was free to view but is now viewable only by subscribers.. Basically, it said that IsNumeric returned True for things like -- currency symbols being located in front or in back of the number as shown in my example (also applies to plus, minus and blanks too); numbers surrounded by parentheses as shown in my example (some people use these to mark negative numbers); numbers containing any number of commas before a decimal point as shown in my example; numbers in scientific notation (a number followed by an upper or lower case "D" or "E", followed by a number equal to or less than 305 -- the maximum power of 10 in VB); and Octal/Hexadecimal numbers (&H for Hexadecimal, &O or just & in front of the number for Octal). NOTE: ====== In the above example and in the referenced tip, I refer to $ signs and commas and dots -- these were meant to refer to your currency, thousands separator and decimal point symbols as defined in your local settings -- substitute your local regional symbols for these if appropriate. -- Rick (MVP - Excel) "Per Jessen" wrote in message ... Hi Look at this example: If isnumeric(MyString) then 'numeric string else 'whatever endif Regards, Per On 22 Jan., 05:59, Fan924 wrote: I have a 10 character number string. I need a test to confirm that there are no non-numeric characters in this string. Thanks Excel97 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
did you try
If IsNumeric(your_variable) Then MsgBox "ok" Else MsgBox "not ok" End If -- Gary Keramidas Excel 2003 "Fan924" wrote in message ... I have a 10 character number string. I need a test to confirm that there are no non-numeric characters in this string. Thanks Excel97 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Please see my response to Per Jessen.
-- Rick (MVP - Excel) "Gary Keramidas" <GKeramidasAtMSN.com wrote in message ... did you try If IsNumeric(your_variable) Then MsgBox "ok" Else MsgBox "not ok" End If -- Gary Keramidas Excel 2003 "Fan924" wrote in message ... I have a 10 character number string. I need a test to confirm that there are no non-numeric characters in this string. Thanks Excel97 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In other words, you are looking for a test to see if your 10 character
number string is made up of digits only, right? Here is a function that will do that... Function IsDigitsOnly(Value As String) As Boolean IsDigitsOnly = Len(Value) 0 And _ Not Value Like "*[!0-9]*" End Function If you want to incorporate this function's code directly within your own code (without needing to call a separate function), then your test would be structured something like this... If Len(TenCharString) 0 And Not TenCharString Like "*[!0-9]*" Then ' TenCharString is made up of digits only Else ' At least one character in TenCharString is not a digit End If -- Rick (MVP - Excel) "Fan924" wrote in message ... I have a 10 character number string. I need a test to confirm that there are no non-numeric characters in this string. Thanks Excel97 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here is the function without making use of the distracting line
continuation.. Function IsDigitsOnly(Value As String) As Boolean IsDigitsOnly = Len(Value) 0 And Not Value Like "*[!0-9]*" End Function -- Rick (MVP - Excel) "Rick Rothstein" wrote in message ... In other words, you are looking for a test to see if your 10 character number string is made up of digits only, right? Here is a function that will do that... Function IsDigitsOnly(Value As String) As Boolean IsDigitsOnly = Len(Value) 0 And _ Not Value Like "*[!0-9]*" End Function If you want to incorporate this function's code directly within your own code (without needing to call a separate function), then your test would be structured something like this... If Len(TenCharString) 0 And Not TenCharString Like "*[!0-9]*" Then ' TenCharString is made up of digits only Else ' At least one character in TenCharString is not a digit End If -- Rick (MVP - Excel) "Fan924" wrote in message ... I have a 10 character number string. I need a test to confirm that there are no non-numeric characters in this string. Thanks Excel97 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Per, Gary, and Rick.
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Test for numeric constant in a cell | Excel Programming | |||
Need to test for alphanumeric value and write numeric values to ce | Excel Worksheet Functions | |||
determinant with non-numeric characters | Excel Discussion (Misc queries) | |||
Deleting non numeric characters. | Excel Programming | |||
"combo box- numeric characters" | Excel Discussion (Misc queries) |