PC Review


Reply
Thread Tools Rate Thread

How to confirm a cell entry is a whole number

 
 
Robert Flanagan
Guest
Posts: n/a
 
      26th Aug 2009
Any suggestions on how to confirm that the value in a cell is a whole
number?

Bob


 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      26th Aug 2009
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)

--
Rick (MVP - Excel)


"smartin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Robert Flanagan wrote:
>> Any suggestions on how to confirm that the value in a cell is a whole
>> number?
>>
>> Bob

>
> Def IsWholeNumber as Boolean
> IsWholeNumber = MyValue = Abs(Int(MyValue))


 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      26th Aug 2009
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.

--
Rick (MVP - Excel)


"smartin" <(E-Mail Removed)> wrote in message
news:mZSdnf-(E-Mail Removed)...
> Rick Rothstein wrote:
>> 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)
>>

>
> My understanding of the definition of "whole numbers" is "the set of
> positive integers, including zero". If the OP meant "integer number", then
> I agree to remove the Abs wrapper in the test, as you suggest.


 
Reply With Quote
 
Phil Hibbs
Guest
Posts: n/a
 
      26th Aug 2009
smartin wrote:
> My understanding of the definition of "whole numbers" is "the set of
> positive integers, including zero". If the OP meant "integer number",
> then I agree to remove the Abs wrapper in the test, as you suggest.


The definition is ambiguous:
http://en.wikipedia.org/wiki/Whole_number

Phil Hibbs.
 
Reply With Quote
 
Bernd P
Guest
Posts: n/a
 
      26th Aug 2009
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a specific row number active from a cell entry Bilbo Baggs Microsoft Excel Misc 15 24th May 2010 06:29 PM
How do I make a cell with vertical lines for number entry? Russ Microsoft Excel Misc 4 21st Feb 2008 03:08 PM
script to increase last number in cell entry for hyperlink kim Microsoft Excel Programming 1 3rd Jan 2008 12:01 PM
automatically multiply each cell entry by a number dnitz Microsoft Excel Misc 1 14th Sep 2004 02:21 AM
Any ideas on how to confirm data entry of an item post entry? Dale C Gray Microsoft Access Forms 3 21st Jul 2003 04:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:57 AM.