Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default IsNumber (in Rick Rothstein's example)

I'm trying to write a function that checks whether an input is a positive
number.

Below is one of Rick Rothstein's examples that he recommands for use in
replacement of IsNumeric. But I need to expand it further so only "positive
whole number or integer" (i.e with or without decimal point) returns true.
While anything else with text, sign or symbol need to return false.

Any help is appreciated.

Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Len(Value) 0 And Not Value Like "*[!0-9.]*"
End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default IsNumber (in Rick Rothstein's example)

Rightfully, the function you posted should have been called IsDigits, not
IsNumber.

Give this function a try...

Function IsNumber(ByVal Value As String) As Boolean
' Uncomment the next statement out if you
' want to provide for plus/minus signs
' If Value Like "[+-]*" Then Value = Mid$(Value, 2)
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) 0 And Value < "." And _
Value < vbNullString
End Function

Rick


"Sam Kuo" wrote in message
...
I'm trying to write a function that checks whether an input is a positive
number.

Below is one of Rick Rothstein's examples that he recommands for use in
replacement of IsNumeric. But I need to expand it further so only
"positive
whole number or integer" (i.e with or without decimal point) returns true.
While anything else with text, sign or symbol need to return false.

Any help is appreciated.

Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Len(Value) 0 And Not Value Like "*[!0-9.]*"
End Function


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default IsNumber (in Rick Rothstein's example)

Try...

Function IsNumber(ByVal Value As String) As Boolean
If (Len(Value) 0 And Not Value Like "*[!0-9.]*") Then
If Value 0 Then
IsNumber = True
Exit Function
End If
End If
IsNumber = False
End Function


Hope this helps,

Hutch

"Sam Kuo" wrote:

I'm trying to write a function that checks whether an input is a positive
number.

Below is one of Rick Rothstein's examples that he recommands for use in
replacement of IsNumeric. But I need to expand it further so only "positive
whole number or integer" (i.e with or without decimal point) returns true.
While anything else with text, sign or symbol need to return false.

Any help is appreciated.

Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Len(Value) 0 And Not Value Like "*[!0-9.]*"
End Function

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default IsNumber (in Rick Rothstein's example)

I just re-read what you wrote and I'm not sure what your question really is
anymore. You wrote "so only 'positive whole number or integer' (i.e with or
without decimal point) returns true"... and so, picking up on the "decimal
point" part (and reading over the rest of what you wrote kind of quickly), I
gave you a function for seeing if an entry is a floating point number or
not. But I now think maybe you are asking about permitting a trailing
decimal point. If that is actually what you want, try this function
instead...

Function IsNumber(ByVal Value As String) As Boolean
If Value Like "." Then Value = Left(Value, Len(Value) - 1)
IsNumber = Len(Value) 0 And Not Value Like "*[!0-9.]*"
End Function

Rick


"Rick Rothstein (MVP - VB)" wrote in
message ...
Rightfully, the function you posted should have been called IsDigits, not
IsNumber.

Give this function a try...

Function IsNumber(ByVal Value As String) As Boolean
' Uncomment the next statement out if you
' want to provide for plus/minus signs
' If Value Like "[+-]*" Then Value = Mid$(Value, 2)
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) 0 And Value < "." And _
Value < vbNullString
End Function

Rick


"Sam Kuo" wrote in message
...
I'm trying to write a function that checks whether an input is a positive
number.

Below is one of Rick Rothstein's examples that he recommands for use in
replacement of IsNumeric. But I need to expand it further so only
"positive
whole number or integer" (i.e with or without decimal point) returns
true.
While anything else with text, sign or symbol need to return false.

Any help is appreciated.

Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Len(Value) 0 And Not Value Like "*[!0-9.]*"
End Function



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default IsNumber (in Rick Rothstein's example)

Below is one of Rick Rothstein's examples that he recommands
for use in replacement of IsNumeric.


Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Len(Value) 0 And Not Value Like "*[!0-9.]*"
End Function


Rightfully, the function you posted should have been called IsDigits, not
IsNumber.


I just noticed... you added a decimal point inside the square-brackets that
I had not included in my original posting. Doing that invalidates the
function... for that modification you did, things like the following will
now pass the test...

Debug.Print IsNumber(".")
Debug.Print IsNumber("...")
Debug.Print IsNumber("1.2.3")

See my other posts in this thread for the function you want.

Rick



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default IsNumber (in Rick Rothstein's example)

Hi Rick

Thanks for your explaination.
Sorry you were right that I was really after IsNumber, not IsDigits of your
example.

I want to only allow positive whole number (without decimal point) and real
number (with decimal point) to return TRUE. For example, the acceptable input
might be 0.25 or 100 say.

Your IsNumber here works great for this purpose. But I also need input with
signs (e.g. $123) or exponential (1E2) to return FALSE. Is this doable?

Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) 0 And Value < "." And _
Value < vbNullString
End Function

Many thanks
Sam




"Rick Rothstein (MVP - VB)" wrote:

Below is one of Rick Rothstein's examples that he recommands
for use in replacement of IsNumeric.

Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Len(Value) 0 And Not Value Like "*[!0-9.]*"
End Function


Rightfully, the function you posted should have been called IsDigits, not
IsNumber.


I just noticed... you added a decimal point inside the square-brackets that
I had not included in my original posting. Doing that invalidates the
function... for that modification you did, things like the following will
now pass the test...

Debug.Print IsNumber(".")
Debug.Print IsNumber("...")
Debug.Print IsNumber("1.2.3")

See my other posts in this thread for the function you want.

Rick


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default IsNumber (in Rick Rothstein's example)

You are going to explain in some detail exactly how you are using this
function. The reason is because the function already returns False for
numbers like $123 and 1E2... that is what it was designed to do.

Rick


"Sam Kuo" wrote in message
...
Hi Rick

Thanks for your explaination.
Sorry you were right that I was really after IsNumber, not IsDigits of
your
example.

I want to only allow positive whole number (without decimal point) and
real
number (with decimal point) to return TRUE. For example, the acceptable
input
might be 0.25 or 100 say.

Your IsNumber here works great for this purpose. But I also need input
with
signs (e.g. $123) or exponential (1E2) to return FALSE. Is this doable?

Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) 0 And Value < "." And _
Value < vbNullString
End Function

Many thanks
Sam




"Rick Rothstein (MVP - VB)" wrote:

Below is one of Rick Rothstein's examples that he recommands
for use in replacement of IsNumeric.

Function IsNumber(ByVal Value As String) As Boolean
IsNumber = Len(Value) 0 And Not Value Like "*[!0-9.]*"
End Function

Rightfully, the function you posted should have been called IsDigits,
not
IsNumber.


I just noticed... you added a decimal point inside the square-brackets
that
I had not included in my original posting. Doing that invalidates the
function... for that modification you did, things like the following will
now pass the test...

Debug.Print IsNumber(".")
Debug.Print IsNumber("...")
Debug.Print IsNumber("1.2.3")

See my other posts in this thread for the function you want.

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
Rick Rothstein Gordy99 Excel Programming 0 February 28th 08 07:05 PM
ISNUMBER Tanya Excel Worksheet Functions 5 December 6th 07 04:45 PM
Question for Rick Rothstein Jenny B. Excel Discussion (Misc queries) 0 June 27th 07 07:06 PM
answer to Rick Axel Excel Programming 7 June 25th 07 09:00 PM
ISNumber VBA trickdos[_9_] Excel Programming 7 July 23rd 04 10:37 PM


All times are GMT +1. The time now is 09:23 PM.

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

About Us

"It's about Microsoft Excel"