tags:

views:

1034

answers:

6

So, to preface, I'm a complete novice at this Excel business. I've found similar examples via Google of how to do this, so I don't think I'm too far off:

=IF( AND(D6=FALSE, OR(ISBLANK(B10),B10=0) ),IF( AND(D6=TRUE,B10>=1)," ","Enter number of components"),"fail")

Essentially, the first IF block evaluates the contents of the AND expression. If that condition passes, I want to evaluate the second IF block (which will echo an error to the cell if the condition fails).

Thanks in advance for your assistance :)

+1  A: 

With something this complex, you should try breaking it up into smaller functions in each cell. A good candidate would be to move the AND into its own cell, and then use that as the first argument of AND. I'm not sure if you can have an IF as a result, so try setting the value_if_true and value_if_false to other cells, and do the individual calculations there.

A. Scagnelli
+2  A: 

according to your code, you are first evaluating if D6=FALSE, when that comes true, you then are trying to evaluate if D6=TRUE. Well from the first evaluation you already know it's false so your logic is flawed.

it seems to me that you may just want to evaluate once

=IF( AND(D6=FALSE, OR(ISBLANK(B10),B10=0) ), "Enter number of components", "Fail")

Russ Bradberry
A: 

First, let's look at the code's structure:

if D6 = false AND (isblank(B10) OR B10 = 0)
  if D6 = true AND B10 >= 1
    put " "
  else
    put "Enter number of components"
else
  put "fail"

One problem you'll find is that every time you enter the inner IF statement, D6 is FALSE. This means D6=TRUE always results in false, so the second IF statement always fails. In other words, your code is equivalent to:

=IF(AND(D6=TRUE, OR(ISBLANK(B10), B10=0)), "Enter number of components", "fail")

Is that not what you want?

Pesto
that's awfully close to my previous answer
Russ Bradberry
A: 
e.James
+1  A: 

I broke down the logic to make it clearer what is going on in the formula. Maybe this will help you piece together how the IF statements work.

if (D6 is false & B10 is blank)
     then if (D6 is true & B10 >= 1)
          then "" THIS WILL NEVER HAPPEN
          else "Enter number of components"
else "fail"
Joel Goodwin
A: 

Turns out this got the job done:

=IF( OR( AND(D6=TRUE,  OR(ISBLANK(B10),B10=0)), AND(D6=FALSE, OR(B10>=1))), "Selection Invalid","")

It appears that trying to nest the second IF within the "THEN" block of the first IF made excel angry. The above works, thanks for the responses!

inkedmn
This is all very confusing. You haven't explained in words what you are actually trying to do, have stated that your above redundancy-riddled formula -- equivalent to IF(IF(D6, OR(ISBLANK(B10), B10=0), B10>=1), "BUDeSYSTEM Selection Invalid", "") -- "works" but have then selected another answer (NOT equivalent to your own!) as "the" answer :-( By the way, does B10 contain only integer values?
John Machin
Nesting an IF within the "THEN" block is perfectly OK. IIRC, Excel (at least up to 2003) allows up to seven levels of nesting. So that couldn't have been your problem. Also, the last "OR" function is unnecessary: evaluating an OR with just one argument is the same as just evaluating the argument. I'm downvoting your answer because honestly it looks to me like you don't know what it's doing or why it works.
John M Gant