Excel IF statement with multiple AND/OR conditions, nested IF formulas, and more

In Part 1 of our Excel IF function tutorial, we started to learn the nuts and bolts of the Excel IF function. As you remember, we discussed a few IF formulas for numbers, dates and text values as well as how to write an IF statement for blank and non-blank cells.

However, for powerful data analysis, you may often need to evaluate multiple conditions at a time, meaning you have to construct more sophisticated logical tests using multiple IF functions in one formula. The formula examples that follow below will show you how to do this correctly. You will also learn how to use Excel IF in array formulas and learn the basics of the IFEFFOR and IFNA functions.

How to use Excel IF function with multiple conditions

In summary, there can be 2 basic types of multiple conditions - with AND and OR logic. Consequently, your IF function should embed an AND or OR function in the logical test, respectively.

  • AND function. If your logical test contains the AND function, Microsoft Excel returns TRUE if all the conditions are met; otherwise it returns FALSE.
  • OR function. In case you use the OR function in the logical test, Excel returns TRUE if any of the conditions is met; FALSE otherwise.

To better illustrate the point, let's have a look at a few IF examples with multiple conditions.

Example 1. Using IF & AND function in Excel

Suppose, you have a table with the results of two exam scores. The first score, stored in column C, must be equal to or greater than 20. The second score, listed in column D, must be equal to or exceed 30. Only when both of the above conditions are met, a student passes the final exam.

The easiest way to make a proper formula is to write down the condition first, and then incorporate it in the logical_test argument of your IF function:

Condition: AND(B2>=20, C2>=30)

IF/AND formula: =IF((AND(C2>=20, D2>=30)), "Pass", "Fail")

Easy, isn't it? The formula tells Excel to return "Pass" if a value in column C >=20 AND a value in column D >=30. Otherwise, the formula returns "Fail". The screenshot below proves that our Excel IF /AND function is correct:
Excel IF function with multiple AND conditions

Note. Microsoft Excel checks all conditions in the AND function, even if one of the already tested conditions evaluates to FALSE. Such behavior is a bit unusual since in most of programming languages, subsequent conditions are not tested if any of the previous tests has returned FALSE.

In practice, a seemingly correct IF / AND formula may result in an error because of this specificity. For example, the formula =IF(AND(A2<>0,(1/A2)>0.5),"Good", "Bad") will return "Divide by Zero Error" (#DIV/0!) if cell A2 is equal to 0. The avoid this, you should use a nested IF function:

=IF(A2<>0, IF((1/A2)>0.5, "Good", "Bad"), "Bad")

Example 2. Using IF with OR function in Excel

You use the combination of IF & OR functions in a similar way. The difference from the IF / AND formula discussed above is that Excel returns TRUE if at least one of the specified conditions is met.

So, if we modify the above formula in the following way:

=IF((OR(C2>=20, D2>=30)), "Pass", "Fail")

Column E will have the "Pass" mark if either the first score is equal to or greater than 20 OR the second score is equal to or greater than 30.

As you see in the screenshot below, our students have a better chance to pass the final exam with such conditions (Scott being particularly unlucky failing by just 1 point : )
An example of IF/OR formula

More formula examples can be found in Excel IF OR functon.

Example 3. Using IF with AND & OR functions

In case you have to evaluate your data based on several sets of multiple conditions, you will have to employ both AND & OR functions at a time.

In the above table, suppose you have the following criteria to evaluate the students' success:

  • Condition 1: column C>=20 and column D>=25
  • Condition 2: column C>=15 and column D>=20

If either of the above conditions is met, the final exam is deemed passed, otherwise - failed.

The formula might seem tricky, but in a moment, you will see that it is not! You just have to express two conditions as AND statements and enclose them in the OR function since you do not require both conditions to be met, either will suffice:

OR(AND(C2>=20, D2>=25), AND(C2>=15, D2>=20)

Finally, use the above OR function as the logical test in the IF function and supply value_if_true and value_if_false arguments. As the result, you will get the following IF formula with multiple AND / OR conditions:

=IF(OR(AND(C2>=20, D2>=25), AND(C2>=15, D2>=20)), "Pass", "Fail")

The screenshot below indicates that we've got the formula right:
Using IF with OR & AND functions

Naturally, you are not limited to using only two AND/OR functions in your Excel IF formulas. You can use as many logical functions as your business logic requires, provided that:

  • In Excel 2016, 2013, 2010 and 2007, your formula includes no more than 255 arguments, and the total length of the formula does not exceed 8,192 characters.
  • In Excel 2003 and lower, you can use up to 30 arguments and the total length of your formula shall not exceed 1,024 characters.

Using multiple IF statements in Excel (nested IF functions)

If you need to create more elaborate logical tests for your data, you can include additional IF statements in the value_if_true and value_if_false arguments of your Excel IF formulas. These multiple IF functions are called nested IF functions and they may prove particularly useful if you want your formula to return 3 or more different results.

Here's a typical example: suppose you want not simply to qualify the students' results as Pass/Fail, but define the total score as "Good", "Satisfactory" and "Poor". For instance:

  • Good: 60 or more (>=60)
  • Satisfactory: between 40 and 60 (>40 and <60)
  • Poor: 40 or less (<=40)

To begin with, you can add an additional column (E) with the following formula that sums numbers in columns C and D: =C2+D2

An additional column that sums numbers in columns C and D

And now, let's write a nested IF function based on the above conditions. It's considered a good practice to start with the most important condition and make your functions as simple as possible. Our Excel nested IF formula is as follows:

=IF(E2>=60, "Good", IF(E2>40, "Satisfactory", "Poor "))

As you see, just one nested IF function is sufficient in this case. Naturally, you can nest more IF functions if you want to. For example:

=IF(E2>=70, "Excellent", IF(E2>=60, "Good", IF(E2>40, "Satisfactory", "Poor ")))

The above formula adds one more conditions - the total score of 70 points and more is qualified as "Excellent".

An example of nested IF functions

For more information about Excel IF with multiple conditions, please see How to use nested IF in Excel.

Using Excel IF in array formulas

Like other Excel functions, IF can be used in array formulas. You may need such a formula if you want to evaluate every element of the array when the IF statement is carried out.

For example, the following array SUM/IF formula demonstrates how you can sum cells in the specified range based on a certain condition rather than add up the actual values:

=SUM(IF(B1:B5<=1,1,2))

The formula assigns a certain number of "points" to each value in column B - if a value is equal to or less than 1, it equates to 1 point; and 2 points are assigned to each value greater than 1. And then, the SUM function adds up the resulting 1's and 2's, as shown in the screenshot below.
Using Excel IF in array formulas

Note. Since this is an array formula, remember to press Ctrl + Shift + Enter to enter it correctly.

Using IF function together with other Excel functions

Earlier in this tutorial, we've discussed a few IF formula examples demonstrating how to use the Excel IF function with logical functions AND and OR. Now, let's see what other Excel functions can be used with IF and what benefits this gives to you.

Example 1. Using IF with SUM, AVERAGE, MIN and MAX functions

When discussing nested IF functions, we wrote the formula that returns different ranking (Excellent, Good, Satisfactory or Poor) based on the total score of each student. As you remember, we added a new column with the formula that calculates the total of scores in columns C and D.

But what if your table has a predefined structure that does not allow any modifications? In this case, instead of adding a helper column, you could add values directly in your If formula, like this:

=IF((C2+D2)>=60, "Good", IF((C2+D2)=>40, "Satisfactory", "Poor "))

Okay, but what if your table contains a lot of individual scores, say 5 different columns or more? Summing so many figures directly in the IF formula would make it enormously big. An alternative is embedding the SUM function in the IF's logical test, like this:

=IF(SUM(C2:F2)>=120, "Good", IF(SUM(C2:F2)>=90, "Satisfactory", "Poor "))
Using IF with the SUM function

In a similar fashion, you can use other Excel functions in the logical test of your IF formulas:

IF and AVERAGE:

=IF(AVERAGE(C2:F2)>=30,"Good",IF(AVERAGE(C2:F2)>=25,"Satisfactory","Poor "))

The formulas retunes "Good" if the average score in columns C:F is equal to or greater than 30, "Satisfactory" if the average score is between 29 and 25 inclusive, and "Poor" if less than 25.

IF and MAX/MIN:

To find the highest and lowest scores, you can use the MAX and MIN functions, respectively. Assuming that column F is the total score column, the below formulas work a treat:

MAX: =IF(F2=MAX($F$2:$F$10), "Best result", "")

MIN: =IF(F2=MIN($F$2:$F$10), "Worst result", "")

If you'd rather have both the Min and Max results in the same column, you can nest one of the above functions in the other, for example:

=IF(F2=MAX($F$2:$F$10) ,"Best result", IF(F2=MIN($F$2:$F$10), "Worst result", ""))
Using IF with the MIN and MAX functions

In a similar manner, you can use the IF function with your custom worksheet functions. For example, you can use it with the GetCellColor / GetCellFontColor functions to return different results based on a cell color.

In addition, Excel provides a number of special IF functions to analyze and calculate data based on different conditions.

For example, to count the occurrences of a text or numeric value based on a single or multiple conditions, you can use COUNTIF and COUNTIFS, respectively. To find out a sum of values based on the specified condition(s), use the SUMIF or SUMIFS functions. To calculate the average according to certain criteria, use AVERAGEIF or AVERAGEIFS.

For the detailed step-by-step formula examples, check out the following tutorials:

Example 2. IF with ISNUMBER and ISTEXT functions

You already know a way to spot blank and non-blank cells using the ISBLANK function. Microsoft Excel provides analogous functions to identify text and numeric values - ISTEXT and ISNUMBER, respectively.

Here's is example of the nested Excel IF function that returns "Text" if cell B1 contains any text value, "Number" if B1 contains a numeric value, and "Blank" if B1 is empty.

=IF(ISTEXT(B1), "Text", IF(ISNUMBER(B1), "Number", IF(ISBLANK(B1), "Blank", "")))
Using IF with ISNUMBER, ISTEXT and ISBLANK functions

Note. Please pay attention that the above formula displays "Number" for numeric values and dates. This is because Microsoft Excel stores dates as numbers, starting from January 1, 1900, which equates to 1.

Example 3. Using the result returned by IF in another Excel function

Sometimes, you can achieve the desired result by embedding the IF statement in some other Excel function, rather than using another function in a logical test.

Here's another way how you can use the CONCATINATE and IF functions together:

=CONCATENATE("You performed ", IF(C1>5,"fantastic!", "good"))

I believe you hardly need any explanation of what the formula does, especially looking at the screenshot below:
Using the result returned by IF in another Excel function

IF function vs. IFERROR and IFNA

Both of the functions, IFERROR and IFNA, are used to trap errors in Excel formulas and replace them with another calculation, predefined value or text message. In earlier Excel versions, you can use the IF ISERROR and IF ISNA combinations instead.

The difference is that IFERROR and ISERROR handle all possible Excel errors, including #VALUE!, #N/A, #NAME?, #REF!, #NUM!, #DIV/0!, and #NULL!. While IFNA and ISNA specialize solely in #N/A errors.

Here is the simplest example of the IFERROR formula:

=IFERROR(B2/C2, "Sorry, an error has occurred")
An example of using the IFERROR function in Excel

As you see in the screenshot above, column D displays the quotient of the division of a value in column B by a value in column C. You can also see two error messages in cells D2 and D5 because everyone knows that you cannot divide a number by zero.

In some cases, however, you may not want to trap all errors, but rather test the condition causing a specific error. For example, to replace a divide by zero error with your own message, use the following IF formula:

=IF(C2=0, "Sorry, an error has occurred", B2/C2)

And that's all I have to say about using the IF function in Excel. I thank you for reading and hope to see you on our blog next week!

You may also be interested in:

1,602 Responses to "Excel IF statement with multiple AND/OR conditions, nested IF formulas, and more"

  1. Vanessa says:

    Hi,

    I have a combination of different type of employee and I want to write the position name in a column. There is 3 types of position : scientist, Head and Analyst. I have too much analysts and it change too often to enter all the names in the formula. Is there a way with my formula to say that if the name does not corresponds to one mentioned, instead of writting ''false'' to write ''Analyst''? Here is my formula with letters instead of names :
    =IF(OR([@Nom]="A",[@Nom]="B",[@Nom]="C",[@Nom]="D",[@Nom]="E",[@Nom]="F",[@Nom]="G",[@Nom]="H",[@Nom]="I",[@Nom]="J", @Nom]="K"),"Scientist",IF(OR([@Nom]="L"),"Head"))

    I tried addind ... ,''Analyst'')) at the end of the formula but excel does not take it.

    Thanks,

  2. wasim says:

    Hi all
    I need help regarding such kind of formula in excel:
    MAX(C1,C2,C3)>1 then A=MAX(C1,C2,C3)+((count of factors>1)-1) * constant
    where C1, C2, C3 values in 3 colums
    Sincere regards
    Waseem

  3. Justin Squires says:

    HELP PLEASE! I have a column recording tshirt sizes and i want to minus one from 100 anytime an XL tshirt size is entered in that tshirt size column. So far i have =IF(D1="XL",E544-1). The number 100 is stored in cell E544 hence using E544-1. Note well, it works for only D1 cell. I want it to work for the entire D column. PLEASE HELP.

  4. adi says:

    I have a value if it is greather than the in a cell it have to take that value in the box

  5. Ram says:

    hi, i need to write a function that tracks progress of a particular invoice through different sheets.
    I have a main sheet that should show numerical values of 25, 50, 75, 100.
    My function works with 2 sheets but if i add on more than that it fails
    the formula for 2 sheets is
    =IF(AND(ISBLANK(Quote!C2),ISBLANK(PO!C2)),"0",
    IF(ISBLANK(PO!C2),"25","50"))
    I have two more sheets that tracks to invoice and payment, would greatly appreciate any help you can give me

  6. Koz says:

    I'm struggling to create an iserror (iferror?) formula that addresses the #DIV/0! that results with the formula below.

    I want to show a blank ("") when the formula results in a #DIV/0! error from the number of days in the month - number of days in the month completed. If the month is completed, this results in a 0, thus, creating the error. How do I just replace the error with a blank ""?

    B4 is the current date and C3 is the start of the current month. In this example, the current month is January.

    =IF(MONTH($B$4)>MONTH(C3),"", IF(MONTH($B$4)=MONTH(C3),(C110-C112)/(eomonth(C3,0)-$B$4), ""))

    B4 = 1/31/19
    C3 = 1/1/19
    C110 - monthly goal
    C112 - monthly actual revenue

    I've been stuck on this for days...please help... :'(

  7. Tharindu says:

    I want to know the if function for below case
    There are two columns and one is some status and it comes with word and it should be filled manually. The other column should be automatically filled with some assigned marks/ points/ numerical value when the first column status are filled. What is the formula for this?
    for example the first column has 4 status as "Not Applicable"," Acceptable", " Need Improvement" and Not Acceptable". The assigned values are for above mentioned 0, 2, 1, -1 respectively. I want to do the formula when I change the Not applicable status in first column then in second column the value assigned to Not applicable (-1) should be automatically filled

  8. shruthi H B says:

    Hello,
    I have a sheet where i need to get data from another sheet where two two conditions are met then only it should take the data. If not it should skip the entire row.
    Please help.
    Column A= Business (A/B)
    Coulmn B= item status (open/closed)
    I need to get only the values of business A with item status closed.

  9. Benjamin says:

    Please write to me a formula on how can i use excel to solve a problem in two columns if I must substitute the greater of the value in the two columns to find the corresponding value in the third column

  10. chandu says:

    =IF(B23=24&B23=30&B23=36&B23=48&B23=60,5))))))

    is above formula is correct iam getting false as result. Please check and suggest

    • James says:

      B23 can only equal one value. You are saying IF it equals 24, AND 30, AND 36, AND 48, AND 60. That is obviously false since none of those values equal each other. Also, why do you have so many closed parentheses at the end?

  11. Cydnee says:

    Hello,
    I have a table of figures in which I am trying to conduct a count of numbers that meet specific criteria (C3:N3,"<"&0.01) BUT if the criteria are not satisfied, the count starts over. For example, I have a row with the following figures:

    0.31% 0.7% 0.95% 0.49% 1.23% 1.14% 3.66% 0.26% 0.7% 1.79% 2.19% 0.93%
    I need the output for this particular string to read '1' because the count is reset as the 11th number is over 1%.

    Additional example:
    1.08% 0.58% 0.87% 0.79% 0.08% 0.20% 1.32% 0.95% 0.08% 0.15% 0.54% 0.44%
    This particular string should output 5 because the count restarts after the 7th number exceeds 1%.

    Thank you,

  12. Anna says:

    Hi, I am trying to find the right IF function but can't quite get it.
    If A1 is greater than or equal to 9, and B1 is zero, then A1 minus 9, else sum of A1+B1. But no matter what I try, it doesn't work. the result is always either deducted or added by 9. Only the value in A1 should be deducted by 9 if its =/> 9. Value in B1 stays as is. Can you please help? thank you.

  13. Chris says:

    Hi,
    Is it possible to Have the cell show "X" or "Y" if it meets the following criteria:
    IF A6=1
    AND
    G5>=D6,G5<=E6 show X
    but if A6=2 show Y otherwise show nothing ?

  14. Ketan Trivedi says:

    Hi Svetlana
    I have got values of time in one column as an output from one of the machine which does some sort of recording. I want to assign the Shift No. against the time value with conditions as under :
    If the Time is between 07:00:01 and 15:30:00 then I should get output as "Shift 1"
    If the Time is between 15:30:01 and 00:00:00 then I should get output as "Shift 2"
    If the Time is between 00:00:01 and 07:00:00 then I should get output as "Shift 3"
    I tried using the If + AND combination however am not able to get the correct shift values
    Can you please help me out.
    Regds
    Ketan Trivedi

  15. mr.beast101 says:

    Hi I have one doubt. I need formula for the below condition.
    lat1 3 N
    lat2 2 S
    dlat 1 ?
    if NORTH=N =S
    if SOUTH>N =S
    if SOUTH=SOUTH =S
    if SOUTH>N= N

    plss help!!!!.

  16. Diane Baker says:

    I submitted this questions previously but don't see it here. Let's try again. I wrote this formulas but it's returning #value!. That may be because it's a mix of text and number qualifiers. Any ideas?
    =IF(AND([Assignment Group Final],"CSD_SERVICES",[Reassignment Count],"0",[Exclusion],""),"TRUE","FALSE")

  17. CHANDRASHEKAR K says:

    I need to split a number in excel. eg 140 then first cell will have 30,70,40 or if the number is less than 100 e.g 80 then the cells should have 30, 50 respectively let me know how to do it

  18. Manjunath Sajjan says:

    Hello,
    I need to use if condition. My scenario here is,
    if 2 cells contains number, it should be Yes else No

Post a comment



Unfortunately, due to the volume of comments received we cannot guarantee that we will be able to give you a timely response. When posting a question, please be very clear and concise. We thank you for understanding!
Ultimate Suite 2018.5 for Excel
60+ professional tools for Excel 2016-2007 to do your daily work
Incredible product, even better tech support…AbleBits totally delivers!
Deborah Bryant
Anyone who works with Excel is sure to find their work made easier
Jackie Lee
The best spent money on software I've ever spent!
Patrick Raugh
Ablebits is a fantastic product - easy to use and so efficient.
Debra Celmer
Excel is at its best now
Annie C.
I don't know how to thank you enough for your Excel add-ins
Jennifer Morningstar
Anybody who experiences it, is bound to love it!
Kumar Nepa
AbleBits suite has really helped me when I was in a crunch!
Nelda Fink
I have enjoyed every bit of it and time am using it
Christian Onyekachi Nwosu
It's the best $100 we've ever spent!
Mike Cavanagh
I love the program, and I can't imagine using Excel without it!
Robert Madsen
One word… WOW!
Dave Brown
Love the products!
David Johnston
It is like having an expert at my shoulder helping me…
Linda Shakespeare
Your software really helps make my job easier
Jeannie C.
Thanks for a terrific product that is worth every single cent!
Dianne Young
I love your product
Brad Gibson
Awesome!!!
Sheila Blanchard