View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1816_] Rick Rothstein \(MVP - VB\)[_1816_] is offline
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