Home » excel » Excel stuck on IF AND OR

Excel stuck on IF AND OR

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’ve been trying to figure this out for about an hour, but just can’t understand how it works despite researching how to use the IF AND OR on Google.

Basically what I am trying to figure out is how to display this:

If the value in E4 is larger than $A$5 AND equal to or larger than $A$9 THEN E4/C3*100 BUT if E4 is larger than $A$5 AND smaller than $A$9 THEN E4/C3*100 WITH a MINUS (-) symbol in front of the displayed result.

I’m still learning how to use Excel, so this is a bit advanced for me. Could somebody explain this please?

How to&Answers:
=IF(AND(E4>$A$5,E4>=$A$9),
     E4/C3*100,
     IF(AND(E4>$A$5,E4<$A$9),
         E4/C3*100))

This IF() statement follows the exact logic you described in your question.

As you are looking for the same result for either scenarios though I would approach this with a single IF():

IF(AND(E4>$A$5,OR(E4>=$A$9,E4<$A$9)),E4/C3*100) – as both results just want E4 to be >$A$5 we don’t need to list this argument twice

But now we can see that the second argument will always be true, so you are in fact only looking for:

IF(E4>$A$5,E4/C3*100)

Answer:

AND takes a number of conditions and returns TRUE if all the conditions equate to TRUE.

You have two AND statements in your formula:

If the value in E4 is larger than $A$5 AND equal to or larger than $A$9

This is written as AND($E$4>$A$5,$E$4>=$A$9) and will return TRUE or FALSE.

Your second AND statement is:

if E4 is larger than $A$5 AND smaller than $A$9

This is written as AND($E$4>$A$5,$E$4<$A$9) and will return TRUE or FALSE.


The IF function will return one of two answers based on a comparison returning TRUE or FALSE (such as the AND statements).

So the IF function is built as =IF(Comparison, Result if TRUE, Result if FALSE).


Your comparison needs two IF functions so that FALSE is returned if E4 is smaller than A5.

=IF(Comparison_1, Result if TRUE, IF(Comparison_2, Result if TRUE, Result if FALSE))

Using your conditions this will be written as (replace the last FALSE with what you want to happen if no conditions are met):

=IF(AND($E$4>$A$5,$E$4>=$A$9),$E$4/$C$3*100,IF(AND($E$4>$A$5,$E$4<$A$9),$E$4/$C$3*100, FALSE))

Answer:

When you need complex IF-THEN statements, you’re automatically going to end up with what we call “nested IF statements” because Excel is funny that way. Here’s the equation you need:

=IF(AND(E4>$A$5,E4>=A9),E4/C3*100,IF(AND(E4>$A$5,E4<$A$9),-E4/C3*100,"HELP"))

The first IF tests your first equation, and if that fails, then we use the “If false” part of the first IF statement to develop our second IF statement. Note, you actually have 3 possible outcomes, but you only described two. Continue to nest IF statements until you have all scenarios accounted for. See my screenshot!
enter image description here