Excel IF statement with multiple conditions

The tutorial shows how to create multiple IF statements in Excel with AND as well as OR logic. Also, you will learn how to use IF together with other Excel functions.

In the first part of our Excel IF tutorial, we looked at how to construct a simple IF statement with one condition for text, numbers, dates, blanks and non-blanks. For powerful data analysis, however, you may often need to evaluate multiple conditions at a time. The below formula examples will show you the most effective ways to do this.

How to use IF function with multiple conditions

In essence, there are two types of the IF formula with multiple criteria based on the AND / OR logic. Consequently, in the logical test of your IF formula, you should use one of these functions:

  • AND function - returns TRUE if all the conditions are met; FALSE otherwise.
  • OR function - returns TRUE if any single condition is met; FALSE otherwise.

To better illustrate the point, let's investigate some real-life formulas examples.

Excel IF statement with multiple conditions (AND logic)

The generic formula of Excel IF with two or more conditions is this:

IF(AND(condition1, condition2, …), value_if_true, value_if_false)

Translated into a human language, the formula says: If condition 1 is true AND condition 2 is true, return value_if_true; else return value_if_false.

Suppose you have a table listing the scores of two tests in columns B and C. To pass the final exam, a student must have both scores greater than 50.

For the logical test, you use the following AND statement: AND(B2>50, C2>50)

If both conditions are true, the formula will return "Pass"; if any condition is false - "Fail".

=IF(AND(B2>50, B2>50), "Pass", "Fail")

Easy, isn't it? The screenshot below proves that our Excel IF /AND formula works right: Excel IF statement with multiple AND conditions

In a similar manner, you can use the Excel IF function with multiple text conditions.

For instance, to output "Good" if both B2 and C2 are greater than 50, "Bad" otherwise, the formula is:

=IF(AND(B2="pass", C2="pass"), "Good!", "Bad") Excel IF function with multiple text conditions

Important note! The AND function checks all the conditions, even if the already tested one(s) evaluated 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 statement may result in an error because of this specificity. For example, the below formula would return #DIV/0! ("divide by zero" error) if cell A2 is equal to 0:

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

The avoid this, you should use a nested IF function:

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

For more information, please see IF AND formula in Excel.

Excel IF function with multiple conditions (OR logic)

To do one thing if any condition is met, otherwise do something else, use this combination of the IF and OR functions:

IF(OR(condition1, condition2, …), value_if_true, value_if_false)

The difference from the IF / AND formula discussed above is that Excel returns TRUE if any of the specified conditions is true.

So, if in the previous formula, we use OR instead of AND:

=IF(OR(B2>50, B2>50), "Pass", "Fail")

Then anyone who has more than 50 points in either exam will get "Pass" in column D. With such conditions, our students have a better chance to pass the final exam (Yvette being particularly unlucky failing by just 1 point :) Excel IF function with multiple OR conditions

Tip. In case you are creating a multiple IF statement with text and testing a value in one cell with the OR logic (i.e. a cell can be "this" or "that"), then you can build a more compact formula using an array constant.

For example, to mark a sale as "closed" if cell B2 is either "delivered" or "paid", the formula is:

=IF(OR(B2={"delivered", "paid"}), "Closed", "")

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

IF with multiple AND & OR statements

If your task requires evaluating several sets of multiple conditions, you will have to utilize both AND & OR functions at a time.

In our sample table, suppose you have the following criteria for checking the exam results:

  • Condition 1: exam1>50 and exam2>50
  • Condition 2: exam1>40 and exam2>60

If either of the conditions is met, the final exam is deemed passed.

At first sight, the formula seems a little tricky, but in fact it is not! You just express each of the above conditions as an AND statement and nest them in the OR function (since it's not necessary to meet both conditions, either will suffice):

OR(AND(B2>50, C2>50), AND(B2>40, C2>60)

Then, use the OR function for the logical test of IF and supply the desired value_if_true and value_if_false values. As the result, you get the following IF formula with multiple AND / OR conditions:

=IF(OR(AND(B2>50, C2>50), AND(B2>40, C2>60), "Pass", "Fail")

The screenshot below indicates that we've done the formula right: IF with multiple AND & OR statements

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

  • In Excel 2007 and higher, you have no more than 255 arguments, and the total length of the IF formula does not exceed 8,192 characters.
  • In Excel 2003 and lower, there are no more than 30 arguments, and the total length of your IF formula does not exceed 1,024 characters.

Nested IF statement to check multiple logical tests

If you want to evaluate multiple logical tests within a single formula, then you can nest several functions one into another. Such functions are called nested IF functions. They prove particularly useful when you wish to return different values depending on the logical tests' results.

Here's a typical example: suppose you want to qualify the students' achievements as "Good", "Satisfactory" and "Poor" based on the following scores:

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

Before writing a formula, consider the order of functions you are going to nest. Excel will evaluate the logical tests in the order they appear in the formula. Once a condition evaluates to TRUE, the subsequent conditions are not tested, meaning the formula stops after the first TRUE result.

In our case, the functions are arranged from largest to smallest:

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

Naturally, you can nest more functions if needed (up to 64 in modern versions). Nested IF statement in Excel

For more information, please see How to use multiple nested IF statements in Excel.

Excel IF array formula with multiple conditions

Another way to get an Excel IF to test multiple conditions is by using an array formula.

To evaluate conditions with the AND logic, use the asterisk:

IF(condition1) * (condition2) * …, value_if_true, value_if_false)

To test conditions with the OR logic, use the plus sign:

IF(condition1) + (condition2) + …, value_if_true, value_if_false)

To complete an array formula correctly, press the Ctrl + Shift + Enter keys together. In Excel 365 and Excel 2021, this also works as a regular formula due to support for dynamic arrays.

For example, to get "Pass" if both B2 and C2 are greater than 50, the formula is:

=IF((B2>50) * (C2>50), "Pass", "Fail") IF array formula with multiple AND conditions

In my Excel 365, a normal formula works just fine (as you can see in the screenshots above). In Excel 2019 and lower, remember to make it an array formula by using the Ctrl + Shift + Enter shortcut.

To evaluate multiple conditions with the OR logic, the formula is:

=IF((B2>50) + (C2>50), "Pass", "Fail") IF array formula with multiple OR conditions

Using IF together with other functions

This section explains how to use IF in combination with other Excel functions and what benefits this gives to you.

Example 1. If #N/A error in VLOOKUP

When VLOOKUP or other lookup function cannot find something, it returns a #N/A error. To make your tables look nicer, you can return zero, blank, or specific text if #N/A. For this, use this generic formula:

IF(ISNA(VLOOKUP(…)), value_if_na, VLOOKUP(…))

For example:

If #N/A return 0:

If the lookup value in E1 is not found, the formula returns zero.

=IF(ISNA(VLOOKUP(E1, A2:B10, 2,FALSE )), 0, VLOOKUP(E1, A2:B10, 2, FALSE))

If #N/A return blank:

If the lookup value is not found, the formula returns nothing (an empty string).

=IF(ISNA(VLOOKUP(E1, A2:B10, 2,FALSE )), "", VLOOKUP(E1, A2:B10, 2, FALSE))

If #N/A return certain text:

If the lookup value is not found, the formula returns specific text.

=IF(ISNA(VLOOKUP(E1, A2:B10, 2,FALSE )), "Not found", VLOOKUP(E1, A2:B10, 2, FALSE)) If #N/A error in VLOOKUP

For more formula examples, please see VLOOKUP with IF statement in Excel.

Example 2. IF with SUM, AVERAGE, MIN and MAX functions

To sum cell values based on certain criteria, Excel provides the SUMIF and SUMIFS functions.

In some situations, your business logic may require including the SUM function in the logical test of IF. For example, to return different text labels depending on the sum of the values in B2 and C2, the formula is:

=IF(SUM(B2:C2)>130, "Good", IF(SUM(B2:C2)>110, "Satisfactory", "Poor"))

If the sum is greater than 130, the result is "good"; if greater than 110 – "satisfactory', if 110 or lower – "poor". Using the IF function with SUM

In a similar fashion, you can embed the AVERAGE function in the logical test of IF and return different labels based on the average score:

=IF(AVERAGE(B2:C2)>65, "Good", IF(AVERAGE(B2:C2)>55, "Satisfactory", "Poor"))

Assuming the total score is in column D, you can identify the highest and lowest values with the help of the MAX and MIN functions:

=IF(D2=MAX($D$2:$D$10), "Best result", "")

=IF(D2=MAX($D$2:$D$10), "Best result", "")

To have both labels in one column, nest the above functions one into another:

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

Likewise, you can use IF together with your custom functions. For example, you can combine it with GetCellColor or GetCellFontColor to return different results based on a cell color.

In addition, Excel provides a number of functions to calculate data based on conditions. For detailed formula examples, please check out the following tutorials:

  • COUNTIF - count cells that meet a condition
  • COUNTIFS - count cells with multiple criteria
  • SUMIF - conditionally sum cells
  • SUMIFS - sum cells with multiple criteria

Example 3. IF with ISNUMBER, ISTEXT and ISBLANK

To identify text, numbers and blank cells, Microsoft Excel provides special functions such as ISTEXT, ISNUMBER and ISBLANK. By placing them in the logical tests of three nested IF statements, you can identify all different data types in one go:

=IF(ISTEXT(A2), "Text", IF(ISNUMBER(A2), "Number", IF(ISBLANK(A2), "Blank", ""))) IF with ISNUMBER, ISTEXT and ISBLANK

Example 4. IF and CONCATENATE

To output the result of IF and some text into one cell, use the CONCATENATE or CONCAT (in Excel 2016 - 365) and IF functions together. For example:

=CONCATENATE("You performed ", IF(B1>100,"fantastic!", IF(B1>50, "well", "poor")))

=CONCAT("You performed ", IF(B1>100,"fantastic!", IF(B1>50, "well", "poor")))

Looking at the screenshot below, you'll hardly need any explanation of what the formula does: Using IF and CONCATENATE

IF ISERROR / ISNA formula in Excel

The modern versions of Excel have special functions to trap errors and replace them with another calculation or predefined value - IFERROR (in Excel 2007 and later) and IFNA (in Excel 2013 and later). 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.

For example, to replace the "divide by zero" error (#DIV/0!) with your custom text, you can use the following formula:

=IF(ISERROR(A2/B2), "N/A", A2/B2) Using IF together with ISERROR

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!

Practice workbook for download

Excel IF multiple criteria - examples (.xlsx file)

4538 comments

  1. Hi I was hoping you could help. I have Today() in cell A1, date in B3, and a formula in cell C3: =$A$1-B3.

    I want to make cell C3 to be BLANK if cell B3 date is blank with no date.

    I want to make cell D3 to be "YES" if C3>14 and "NO" if less. However, if cell C3 is blank, D3 also should be blank

    Have tried in cell C3 =IF(ISBLANK(B3), "", $A$1-B8) and in cell D3 =IF(C3>14, "YES","NO").

    The cell C3 does return blank however, cell D3 does not, the problem is Today() in cell A1 is returning a value which mean the cell is not empty. I checked by using =IF(ISBLANK(K8), "TRUE", "FALSE"), the answer is False.

    Please kindly help

    • Hello!
      The formula below will do the trick for you:
      C3 ---
      =IF(ISBLANK(B3),"",A1-B3)
      D3 ---
      =IF(ISBLANK(B3),"",IF(A1-B3 > 14,"Yes","No"))

      Hope this is what you need.

  2. Hi there hoping someone can help me im trying put in a formula that looks at the 2 columns before and depending if a=x b=y then = z

    so as an example ive changed the words to colours(as its for work so privacy rules)

    =IF(($H$2=Red), AND($I$2=Yellow), THEN($J$2="Orange"))

    Red and yellow = orange
    but Red and blue = brown

    Please help! :)

    • Hello!
      I hope you have studied the recommendations in the tutorial above. It contains answers to your question.

      =IF(AND(H2="red",I2="yellow"),"orange","")

  3. Hi Alexander,
    I require your help on below on Excel.

    Delta MOQ To Order per MOQ
    -150 200 200

    Delta MOQ To Order per MOQ
    -300 200 How to use "f" function to auto 2x200=400

    Thanks

    • Hello!
      Sorry, it's not quite clear what you are trying to achieve. Could you please describe it in more detail? What result do you want to get? Give an example of the source data and the expected result.

  4. Hi I have a data validation list In cell A1 that has 2 options, "completed" and "not completed". In cell B1 I have a conditional formatted data bar that represents 0 to 100%. How do I use the IF function so that by selecting Completed the formatted data bar changes to 100% and likewise "not completed" it changes to 0%. This is for a task assignment tracker.

  5. Evening to you

    I require your help with a certain dilemma. My task is two parted, to compare which month has the most expenses and to display that month in an adjacent cell.

    The first part of the task is rather simple using the MAX and possibly the IF function if needed. The part I struggle with is displaying the month which satisfies the first criteria.

    In order for you to assist me, I must provide you with the full details. I can not do that here as I can not attach any file here. However, on any email address it is a different outcome altogether.

    Regards
    Jack

    • Hi!
      Describe your task in more detail and send us a small sample workbook with the source data and expected result to support@ablebits.com. Please shorten your tables to 10-20 rows/columns and include the link to your blog comment.
      We'll look into your task and try to help.

  6. HI,

    I am trying to write a formula with 2 conditions to meet a value and if not return a different value.

    I am asking to look up if cell = UK Mainland and if 2nd cell is = Supply and Install return a value of "55", if not return a value "33 or 50 check origin". The formula is not working see below:

    =IF(and(H12="Mainland UK",L12="Supply & Install", "55", "33 or 50 check origin"))

    I am getting error:

    Not trying to type a formula?

    When the first character is an equal (=) or minus (-) sign, excel thinks it's a formula:

    you type = 1+1, cell shows: 2

    to get around this, type an apostrophe ( ' ) first:

    you type '=1+1, cell shows : 1+1

    I have tried this and its not working, does anyone have a solution please.

    Thanks

    Paul

    • Hello!
      Please try the following formula:

      =IF(AND(H12="Mainland UK",L12="Supply & Install"), "55", "33 or 50 check origin")

      I hope it’ll be helpful.

      • Thanks Alexander. I tried that and it didn't work for me, getting the same error message as per my original post.

        Any other ideas on how to return the formula using the apostrophe function?

        Thanks Paul

          • Hi Alexander,

            Its working now, thanks. There was an issue with excel spreadsheet. I closed it and re did the formula and it works.

            Thanks You.

  7. #need help
    I would like to request the help of (if function)
    Annual leave: if the join date over equal 36 months will get 1 if the join date over equal 72 months will get 2, if the join date over or equal 108 months will get 3,
    so what're formulas that can show anwser:

    Join date: 01/January/2018 : 38months will get 1
    01/January/2015 :74months will get 2
    01/January/2012 :74months will get 3

  8. You work as an Excel specialist in an organization. You want to test the condition that if A1 is greater than 150 and B1 is less than 250 then the function returns 20, otherwise, it should return 0. Which of the following formulas will you apply to test this condition?

  9. Hi,
    Could you help me with this:
    How to allow Data Entry in column B in Excel only if a Dependent column A is Filled with yes (vs no)?

  10. Hi

    How can we use if, and or or for date which is between start date and end date

    I.e. 1/6/2002 is 18 year

    Start date 1/1/2002
    End date 31/1/2002

    And so on for 17 years / 16 years etc...

  11. I have a spreadsheet with 12 columns. I'd like to write a formula that will change column I to "yes" when the value in column F falls below the number in it. How do I write that please?

  12. I need a formula with multiple conditions.
    If "No" and none of 4 cells are <-49.9%, then "1", if "No" and none of 4 cells are between -49.9% and -24.9%, then "2", if "Yes" and none of 4 cells are <-49.9%, then "3", and if "Yes" and none of the 4 cells are between -49.9% and 24.9%, then"4".

  13. Looking at a formula that has more than 0 digits in a single cell, we have to add the value of a fixed cell.
    LIKE IN C2:C10 C5 ,C8 CELL VALUE IS MORE THEN 0, THEN I HAVE COUNT IN B2:B10 VALUE,
    But the value which has more than 0 digits is the value of cell B2: B10.

  14. Can anyone please help me get this formula right. My conditions are, If A2 value (Percentage value) is lower or higher than B2 value (Percentage value) by 2-5% then C2 should say False.

    • If A2 value = B2 value or if A2 and B2 value difference is just +/-1% then C2 should say Pass

      • Thank you, it worked for me

  15. Have three columns and conditional formatting applied across all rows. Conditions for column 1 are >0 is green, between 0 and -20 is yellow, and <-20 is red, similar conditions for columns 2 and 3.

    I'm trying to create a conditional formatting formula that will look at all three instances in a row and if I have a combination of colors for the three columns, output an overall color. 3 greens = green, 3 reds = red, 3 yellows = yellow, 2 greens and a yellow = no formatting, 2 yellows and a red = orange.

    I've tried several different formulas using if(AND( statements, but given greater than two variables, but not always coming out accurate. Any help is appreciated.

  16. Can someone help with this formula. The last part of it doesn't seem to draw in my data.

    =IF($X3='VAL CLASS CATEGORY'!$E$2,VLOOKUP('R&M Detail'!$N3,'Level Lookup'!$A:$F,3,FALSE),IF($Y3='WO PM Desc Lookup'!$J$1,VLOOKUP('R&M Detail'!$AB3,'WO PM Desc Lookup'!$A:$C,3,FALSE),IF($Y3='COST CENTER LOOKUP'!$H$1,VLOOKUP('R&M Detail'!$D3,'COST CENTER LOOKUP'!$A:$C,3,FALSE))))

    • Hi,
      It is very difficult to understand a formula that contains unique references to your workbook worksheets. Hence, I cannot check its work, sorry.
      Unfortunately, without seeing your data it is difficult to give you any advice. Please provide me with an example of the source data and the expected result.

      • Yes , will try.

        The formula is trying to categorize each expense based on three variables: "Val Class Category," "WO PM Desc Lookup," and "Cost Center Lookup" number.

        For instance, First part of formula looks up the item based on the Material number (I have list of materials within the "Level Lookup.") if "val Class Category matches" "$X3" (which it has two options).

        =IF($X3='VAL CLASS CATEGORY'!$E$2,VLOOKUP('R&M Detail'!$N3,'Level Lookup'!$A:$F,3,FALSE),

        This applies to all three parts of the formula

        IF($Y3='WO PM Desc Lookup'!$J$1,VLOOKUP('R&M Detail'!$AB3,'WO PM Desc Lookup'!$A:$C,3,FALSE),

        IF($Y3='COST CENTER LOOKUP'!$H$1,VLOOKUP('R&M Detail'!$D3,'COST CENTER LOOKUP'!$A:$C,3,FALSE))))

        - The problem is with the last part of the formula. It no longer categorizes any item based on the cost center even though there is a cost center number that it can categorize it from.
        - My thinking is that either the first part or second part of the formula is overriding the last one.

        Reply

        • Nevermind, I figured out the problem.

        • Hi,
          I cannot check the formula that contains unique references to your workbook worksheets.
          However, it seems to me that the formula below will work for you:

          =IF($X3='VAL CLASS CATEGORY'!$E$2,VLOOKUP('R&M Detail'!$N3,'Level Lookup'!$A:$F,3,FALSE),
          IF($Y3='WO PM Desc Lookup'!$J$1,VLOOKUP('R&M Detail'!$AB3,'WO PM Desc Lookup'!$A:$C,3,FALSE),
          IF($Y3='COST CENTER LOOKUP'!$H$1,VLOOKUP('R&M Detail'!$D3,'COST CENTER LOOKUP'!$A:$C,3,FALSE),"")))

          I have already written to you what you need to check the work of your formula.

  17. Can anyone solve this issue to use the below three different arguments in one cell?

    =IF(OR(D8="1450Friday",D8="1450Saturday"), 6.14, 5.12)
    =IF(OR(D8="1000Friday",D8="1000Saturday"), 6.14, 5.12)
    =IF(OR(D8="900Friday",D8="900Saturday"), 6.14, 5.12)

    Thanks

    • Hi,
      If you wanted to combine all conditions in one formula, then try this:

      =IF(OR(OR(D8="1450Friday",D8="1450Saturday"), OR(D8="1000Friday",D8="1000Saturday"), OR(D8="900Friday",D8="900Saturday")), 6.14, 5.12)

      Hope this is what you need.

  18. I have a spreadsheet which has a list of employee numbers and required proficiencies along the top. I have a formula which puts a Y if the person has that proficiency (based off a data sheet). But I would like to make a formula which tells me if someone is qualified based off their proficiencies held . For example one of the variables:

    If employee has a Y under prof 1, prof 2, prof 3 ect (through to prof 12) and they also hold prof 13 or 14, and hold prof 15 or 16 or 17, and hold prof 18 or 19 or 20, and hold prof 21 or 22 or 23 then they are marked as yes otherwise they are marked as no

    I am using Excel 16 so I can't use IFS formulas

    • Further to my last comment, what would be the most efficient formula for marking "Y" if they have the proficiency. I currently use:
      =IF(ISERROR(VLOOKUP($A6&J$5,PROFRPT,1,0)),"","Y")

      On the reporting tab in column A I have the formula =B2&L2 and the name manager PROFRPT:
      ='Proficiency Report'!$A$2:INDEX('Proficiency Report'!$A:$A, COUNTA('Proficiency Report'!$A:$A))

      Although I get really large lag with calculating. To the point where sometimes I can even save and exit the workbook for hours because it's caculating

    • Hello!
      Without seeing your data it is difficult to give you any advice. I recommend using the SUMPRODUCT function as described in this article.
      I hope this will help, otherwise please do not hesitate to contact me anytime.

  19. hi i need to do calculation in multiple cell
    m3=>1 then 1,m3>=2 then 2, m3>=3 then 3 and so on till 9
    pls help

  20. 01,02,03....... these numbers are (month) / 001,002,003......these numbers are (serial number)

    01/001= for this numbers/equation somebody please let me know the formula for this.

    Thank you

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)