Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple IF AND statements excel

Tags:

excel

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)
like image 477
DavidJB Avatar asked Apr 02 '13 00:04

DavidJB


People also ask

Can you do multiple if and statements in Excel?

While Excel will allow you to nest up to 64 different IF functions, it's not at all advisable to do so.

Can you do multiple if and statements?

Answer:To write your IF formula, you need to nest multiple IF functions together in combination with the AND function.

Can you use if and and/or together in Excel?

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.


1 Answers

Consider that you have multiple "tests", e.g.,

  1. If E2 = 'in play' and F2 = 'closed', output 3
  2. If E2 = 'in play' and F2 = 'suspended', output 2
  3. Etc.

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))))

like image 176
David Zemens Avatar answered Sep 29 '22 11:09

David Zemens