I need to write an "if" statement in Excel based on text in two different cells.
If E2 ='in play' and F2 ='closed' output 3
If E2= 'in play' and F2 ='suspended' output 2
If E2 ='In Play' and F2 ='Null' output 1
If E2 ='Pre-Play' and F2 ='Null' output -1
If E2 ='Completed' and F2 ='Closed' output 2
If E2 ='Suspended' and F2 ='Null' output 3
If anything else output -2
where Null is no value in the cell
I was trying to do this with the code below but I can't seem to get two or more IF AND statements working together. How can I solve this problem?
=IF(AND(E2="In Play",F2="Closed"),3, -2), IF(AND(E2="In Play",F2=" Suspended"),3,-2)
While Excel will allow you to nest up to 64 different IF functions, it's not at all advisable to do so.
Answer:To write your IF formula, you need to nest multiple IF functions together in combination with the AND function.
IF is one of the most popular Excel functions and very useful on its own. Combined with the logical functions such as AND, OR, and NOT, the IF function has even more value because it allows testing multiple conditions in desired combinations.
Consider that you have multiple "tests", e.g.,
What you really need to do is put successive tests in the False
argument. You're presently trying to separate each test by a comma, and that won't work.
Your first three tests can all be joined in one expression like:
=IF(E2="In Play",IF(F2="Closed",3,IF(F2="suspended",2,IF(F2="Null",1))))
Remembering that each successive test needs to be the nested FALSE argument of the preceding test, you can do this:
=IF(E2="In Play",IF(F2="Closed",3,IF(F2="suspended",2,IF(F2="Null",1))),IF(AND(E2="Pre-Play",F2="Null"),-1,IF(AND(E2="completed",F2="closed"),2,IF(AND(E2="suspended",F2="Null"),3,-2))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With