Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do i get only whole numbers for a formula result?

I am working with one of our engineers that wants to have a cell with a
formula show only whole numbers. He does not want rounding, but to be able
to code a statement that will error out if the result is a deciaml or
fraction. I looked at the Data - validation properties, but it only works
with an entered number not a formula. Is there a simple way to do it without
having to write a program in vb?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default How do i get only whole numbers for a formula result?

For the formula try:

=If(Mod(A1/B1,1)0, "Error",A1/B1)

Or you can use Mod in a conditional format and change the cell format if in
error.
--
rand451
"mkirkley" wrote in message
...
I am working with one of our engineers that wants to have a cell with a
formula show only whole numbers. He does not want rounding, but to be
able
to code a statement that will error out if the result is a deciaml or
fraction. I looked at the Data - validation properties, but it only works
with an entered number not a formula. Is there a simple way to do it
without
having to write a program in vb?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default How do i get only whole numbers for a formula result?

One way:

Say the formula is

=B1/A1

Then you could use

=IF(MOD(B1/A1,1)=0, B1/A1,"Error")

However, due to XL's internal rounding, it's possible to have small
remainders (e.g., 15.0000000000001).

For that reason it's usually best to compare the result of the formula
to a small value that is larger than the largest expected error, but
significantly smaller than the expected result. For instance:

=IF(MOD(B1/A1,1)<0.000000000001, ROUND(B1/A1,0), "Error")

See http://cpearson.com/excel/rounding.htm for more on rounding errors

In article ,
"mkirkley" wrote:

I am working with one of our engineers that wants to have a cell with a
formula show only whole numbers. He does not want rounding, but to be able
to code a statement that will error out if the result is a deciaml or
fraction. I looked at the Data - validation properties, but it only works
with an entered number not a formula. Is there a simple way to do it without
having to write a program in vb?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do i get only whole numbers for a formula result?

=if(trunc(formula)<formula,"Error",formula)

--
Regards,
Tom Ogilvy


"mkirkley" wrote in message
...
I am working with one of our engineers that wants to have a cell with a
formula show only whole numbers. He does not want rounding, but to be

able
to code a statement that will error out if the result is a deciaml or
fraction. I looked at the Data - validation properties, but it only works
with an entered number not a formula. Is there a simple way to do it

without
having to write a program in vb?



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
I need a formula to add numbers to the result in same cell. marciahays Excel Worksheet Functions 1 January 21st 09 07:19 PM
omit numbers past decimal in formula result DebC Excel Worksheet Functions 6 September 25th 08 06:19 PM
Format Result of a Formula Combining Text & Numbers Brad Excel Discussion (Misc queries) 3 April 3rd 07 10:42 PM
How do I convert formula result into numbers so I can sum results? Barsha Excel Discussion (Misc queries) 1 November 11th 06 07:18 PM
Rounding numbers then doing a sum of those numbers produces incorrect result. GzusRox Excel Programming 2 July 26th 03 01:42 PM


All times are GMT +1. The time now is 12:52 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"