IF function

Copper Contributor

Hello gang, I was wondering if anyone could help me with a problem I'm struggling with. Using the IF function in this way: =IF(B8=4,0,IF(B8=3,-10,IF(B8=2,-25,IF(B8=1,-50,IF(B8=5,-15,IF(B8=6,-25,IF(B8=0,"n/a"))))))), where the reference cell (B8) is connected to an external sheet, I get the correct output, i.e. -25 for 2, but when I try to copy the formula down I get a "False" return. I've double checked the reference cells adjusted correctly.

Any hints?

Cheers

3 Replies

@cadco1968 

 

Because there's a connection to an external sheet, there's some ambiguity here...where/what is that external reference? How does the formula, copied down, still connect with external references (note the plural there)?

 

So some additional info there could help...

 

But also, you maybe should investigate the CHOOSE function. It could be better than deeply nested IF functions.

=CHOOSE(B8+1,"N/A",-50,-25,-10,0,-15,-25)

https://exceljet.net/excel-functions/excel-choose-function

 

@cadco1968 

 

IMHO, the "connection" (reference) to an "external"(?) worksheet (i.e, another worksheet in the same workbook?) is irrelevant.

 

All that matters is the values (not the formulas) in the cells in column B.

 

When the formula is copied down, the references to B8 change to B9, B10, B11 etc.

 

So the question that needs to be asked is:  what are the values in B9, B10, B11 etc?

 

-----

 

Presumably, they are not any of the numeric values zero through 6.

 

If that is expected, the problem is simple:  your formula does not cover that case.

 

And you have not told us what you want the result to be in that case.

 

Certainly, your formula can be (and should be) improved.  But at a minimum, perhaps one the following does what you want:

 

=IF(B8=4,0,IF(B8=3,-10,IF(B8=2,-25,IF(B8=1,-50,IF(B8=5,-15,

IF(B8=6,-25,"n/a"))))))

or

=IF(B8=4,0,IF(B8=3,-10,IF(B8=2,-25,IF(B8=1,-50,IF(B8=5,-15,

IF(B8=6,-25,IF(B8=0,"n/a","")))))))

 

The first formula displays "n/a" when the value in column B is none of 1 through 6, including zero.

 

The second formula displays the null string (the cell appears blank) when the value in B is none of zero through 6.  Replace the null string ("") with anything else you would like.

 

-----

 

If you expect that all of the values in column B are zero through 6, you need to investigate why that is not the case.

 

First, confirm that they are indeed numeric.

 

Use a formula like =ISNUMBER(B9).  Looks can be deceiving.  And the format of the cell does not matter.  We can have text that looks like a number in a cell that is formatted as General, Number, Currency etc.  It is still text.

 

Second, if the data are indeed numeric, they might appear to be zero through 6 due to formatting limitations, but in fact they are not exactly.

 

Temporarily format the cells to display 15 decimal places.  That might reveal unintended decimal fractions.

 

But sometimes, there are infinitesimal differences (decimal fractions beyond 15 decimal places) that we cannot see because Excel formats only up to 15 significant digits.

 

One way to discover the infinitesimal differences is with a formula like

=SUM(B9, -ROUND(B9,15)), formatted as General or Scientific (preferred).

 

(FYI, we cannot rely on a simpler formula like =B9-ROUND(B9,15) because of a flawed behavior of Excel that is designed to hide infinitesimal differences.  Klunk!)

 

The infinitesimal differences might be of the form 1.23E-16.  That means 1.23 times 10 to the -16 power (1/10^16).

 

-----

 

If you need further help in troubleshooting the problem, please attach an example Excel file that demonstrates the problem.  Click the "browse" link below.

 

If the forum does not allow you to attach a file, upload the Excel file to a file-sharing website, and post the download URL.  I like box.net/files; others like dropbox.com.

@cadco1968  wrote: ``the reference cell (B8) is connected to an external sheet [....] when I try to copy the formula down I get a "False" return``

 

I have explained why you are getting the FALSE return and a minimal way to fix the IF() formula to avoid it.

 

But I am still struggling to make sense of this.  Specifically, why do you think there is any relationship between any reference in B8 ("external" or not) and the behavior of the IF() formula that you are copying down, which references B8?

 

Perhaps the issue is the interpretation of the phrase "the formula".

 

Suppose your IF() formula is in C8.  I assume you are copying down just C8.

 

But did you mean to say (this is a stretch) that you are copying down both B8 and C8?!

 

If so, then of course we must see the formula in B8 in order to help you.