How to confirm a cell entry is a whole number

  • Thread starter Thread starter Robert Flanagan
  • Start date Start date
R

Robert Flanagan

Any suggestions on how to confirm that the value in a cell is a whole
number?

Bob
 
I'm pretty sure you don't want the Abs function in there (at least not how
you used it). What is wrong with just this....

IsWholeNumber = MyValue = Int(MyValue)
 
Okay, I see what you are doing... you are using the Abs value function to
filter out the negative values (forcing a False for them). Ok, as long as
the OP's understanding of "whole numbers" is the same as yours, your
statement is fine.
 
Hello Bob,

Function IsWhole(r As Range) As Boolean
'TRUE if all values in range are whole numbers, FALSE if not.
Dim v, b As Boolean
For Each v In r
If v.Value <> CLng(v.Value) Then
IsWhole = False
Exit Function
End If
Next v
IsWhole = True
End Function

Here a whole number is a valid LONG number.
Change Clng to Int if you want to accept numbers > 1E15 as well.

Regards,
Bernd
 
Back
Top