Thread: [Solved] ** Excel Formula
View Single Post
 
Old 03-24-2011, 02:30 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Jan 2011
Location: UK
Posts: 369
Colin Legg will become famous soon enough
Default

Hi,

Quote:
Can you explain to me what each section of the formula means?
Sure.

First of all, we need a way to check if the number is a whole number. Excel doesn't have a built-in which will do that. However, it does have a few functions which can be used to remove the decimal portion of a number: the most common would be INT() and TRUNC(), but there are also various rounding functions too (such as ROUND(), ROUNDDOWN(), etc....). The logic I used was to take the number from each cell, remove the decimal portion of the number and then check to see if that is equal to the original number: if it is then the number must be a whole number:
Code:
=IF(TRUNC(A1)=A1,"A1 is a whole number","A1 is not a whole number")
I used TRUNC() rather than INT() so that this test would also work on negative numbers.


From there, it's just a case of applying the correct logic for the possible outcomes:
  • Assume that at least one number must be whole
  • Assume that we don't have to worry about empty cells
  • If A1 and B1 are whole numbers, take the minimum value.
  • Else, If A1 is whole and B1 is not whole then return A1.
  • Else, A1 is not whole so B1 must be whole, so return B1.
Code:
=IF(TRUNC(A1)=A1,IF(TRUNC(B1)=B1,MIN(A1,B1),A1),B1)
Reply With Quote