Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default test to confirm non-numeric characters

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default test to confirm non-numeric characters

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default test to confirm non-numeric characters

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default test to confirm non-numeric characters

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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default test to confirm non-numeric characters

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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default test to confirm non-numeric characters

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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default test to confirm non-numeric characters

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default test to confirm non-numeric characters

Thanks Per, Gary, and Rick.
Reply
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
Test for numeric constant in a cell XP Excel Programming 2 October 21st 08 10:54 PM
Need to test for alphanumeric value and write numeric values to ce Pyramid 36 Excel Worksheet Functions 3 August 3rd 07 03:15 AM
determinant with non-numeric characters aswang Excel Discussion (Misc queries) 0 October 8th 06 12:12 AM
Deleting non numeric characters. CyndyG Excel Programming 2 May 4th 05 10:50 PM
"combo box- numeric characters" adam.ronalds Excel Discussion (Misc queries) 1 February 16th 05 02:14 AM


All times are GMT +1. The time now is 08:18 PM.

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"