Excel nested IF statement - multiple conditions in a single formula

The tutorial explains how to use multiple IF in Excel and provides a couple of nested If formula examples for most common tasks.

If someone asks you what Excel function you use most often, what would your answer be? In most cases, it's the Excel IF function. A regular If formula that tests a single condition is very straightforward and easy to write. But what if your data requires more elaborate logical tests with multiple conditions? In this case, you can include several IF functions in one formula, and these multiple If statements are called Excel Nested IF. The biggest advantage of the nested If statement is that it allows you to check more than one condition and return different values depending on the results of those checks, all in a single formula.

Microsoft Excel has limits to the levels of nested IFs. In Excel 2003 and lower, up to 7 levels were allowed. In Excel 2007 and higher, you can nest up to 64 IF functions in one formula.

Further on in this tutorial, you will find a couple of Excel nested If examples along with a detailed explanation of their syntax and logic.

Example 1. Classic nested IF formula

Here's a typical example of Excel If with multiple conditions. Supposing you have a list of students in column A and their exam scores in column B, and you want to classify the scores with the following conditions:

  • Excellent: Over 249
  • Good: between 249 and 200, inclusive
  • Satisfactory: between 199 and 150, inclusive
  • Poor: Under 150

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

=IF(B2>249, "Excellent", IF(B2>=200, "Good", IF(B2>150, "Satisfactory", "Poor")))

And works exactly as it should:
Classic nested IF formula

Understanding Excel nested IF logic

I've heard some people say that Excel multiple If is driving them crazy :) Try looking at it at a different angle:
Nested If formula logic

What the formula actually tells Excel to do is to evaluate the logical_test of the first IF function and, if the condition is met, return the value supplied in the value_if_true argument. If the condition of the 1st If function is not met, then test the 2nd If statement, and so on.

IF(check if B2>=249, if true - return "Excellent", or else
IF(check if B2>=200, if true - return "Good", or else
IF(check if B2>150, if true - return "Satisfactory", if false -
return
"Poor")))

If you need a nested IF formula with wildcard characters (partial match), check out this example: If cell contains, then return different values.

Example 2. Multiple If with arithmetic calculations

Here's another typical task: the unit price varies depending on the specified quantity, and your goal is to write a formula that calculates the total price for any amount of items input in a specific cell. In other words, your formula needs to check multiple conditions and perform different calculations depending on what amount range the specified quantity falls in:

Unit Quantity Price per unit
1 to 10 $20
11 to 19 $18
20 to 49 $16
50 to 100 $13
Over 101 $12

This task can also be accomplished by using multiple IF functions. The logic is the same as in the above example, the only difference is that you multiply the specified quantity by the value returned by nested IFs (i.e. the corresponding price per unit).

Assuming the user enters the quantity in cell B8, the formula is as follows:

=B8*IF(B8>=101, 12, IF(B8>=50, 13, IF(B8>=20, 16, IF( B8>=11, 18, IF(B8>=1, 20, "")))))

And the result will look something similar to this:
Nested IF formula to perform different calculations on numbers within a certain range

As you understand, this example demonstrates only the general approach, and you can easily customize this nested If function depending on your particular task.

For example, instead of "hard-coding" the prices in the formula, you can reference the cells containing those values (cells B2 to B6). This will enable your users to edit the source data without having to update the formula:

=B8*IF(B8>=101,B6, IF(B8>=50, B5, IF(B8>=20, B4, IF( B8>=11, B3, IF(B8>=1, B2, "")))))
An improved formula with multiple IF functions

Or, you may want to include an additional IF function(s) that fixes an upper, lower or both bounds of the amount range. When the quantity is outside the range, the formula will display an "out of the range" message. For example:

=IF(OR(B8>200,B8<1), "Qty. out of range", B8*IF(B8>=101,12, IF(B8>=50, 13, IF(B8>=20, 16, IF( B8>=11, 18, IF(B8>=1, 20, ""))))))
Nested IF's formula with fixed bounds

The nested IF formulas described above work in all versions of Excel. In Excel 365 and Excel 2021, you can also use the IFS function for the same purpose.

Advanced Excel users that are familiar with array formulas, can use this formula that basically does the same thing as the nested IF function discussed above. Though the array formula is far more difficult to comprehend, let along to write, it has one indisputable advantage - you specify the range of cells containing your conditions rather than referencing each condition individually. This makes the formula more flexible, and if your users happen to change any of the existing conditions or add a new one, you will only have to update a single range reference in the formula.

Excel nested IF - tips and tricks

As you have just seen, there is no rocket science in using multiple IF in Excel. The following tips will help you improve your nested IF formulas and prevent common mistakes.

Nested IF limits

In Excel 2007 - Excel 365, you can nest up to 64 IF functions. In older versions of Excel 2003 and lower, up to 7 nested IF functions can be used. However, the fact that you can nest a lot of IFs in one formula doesn't mean you should. Please keep in mind that each additional level makes your formula more difficult to understand and troubleshoot. If your formula has too many nested levels, you may want to optimize it by using one of these alternatives.

The order of nested IF functions matters

The Excel nested IF function evaluates the logical tests in the order they appear in the formula, and as soon as one of the conditions evaluates to TRUE, the subsequent conditions are not tested. In other words, the formula stops after the first TRUE result.

Let's see how it works in practice. With B2 equal to 274, the nested IF formula below evaluates the first logical test (B2>249), and returns "Excellent" because this logical test is TRUE:

=IF(B2>249, "Excellent", IF(B2>=200, "Good", IF(B2>150, "Satisfactory", "Poor")))

Now, let's reverse the order of IF functions:

=IF(B2>150, "Satisfactory", IF(B2>200, "Good", IF(B2>249, "Excellent", "Poor")))

The formula tests the first condition, and because 274 is greater than 150, the result of this logical test is also TRUE. Consequently, the formula returns "Satisfactory" without testing other conditions.

You see, changing the order of IF functions changes the result:
The order of nested IF functions matters

Evaluate the formula logic

To watch the logical flow of your nested IF formula step-by-step, use the Evaluate Formula feature located on the Formula tab, in the Formula Auditing group. The underlined expression is the part currently under evaluation, and clicking the Evaluate button will show you all the steps in the evaluation process.

For example, the evaluation of the first logical test of the nested IF formula shown in the screenshot below will go as follows: B2>249; 274>249; TRUE; Excellent.
Watch the logical flow of your nested IF formula by using the Evaluate Formula feature.

Balance the parenthesis of nested IF functions

One of the main challenges with nested IFs in Excel is matching parenthesis pairs. If the parentheses do not match, your formula won't work. Luckily, Microsoft Excel provides a couple of features that can help you to balance the parentheses when editing a formula:

  • If you have more than one set of parentheses, the parenthesis pairs are shaded in different colors so that the opening parenthesis matches the closing one.
  • When you close a parenthesis, Excel briefly highlights the matching pair. The same bolding, or "flickering", effect is produced when you move through the formula by using the arrow keys.

Balance the parenthesis of nested IF functions

For more information, please see Match parenthesis pairs in Excel formulas.

Treat text and numbers differently

When building logical tests of your nested IF formulas, remember that text and numbers should be treated differently - always enclose text values in double quotes, but never put quotes around numbers:

Right: =IF(B2>249, "Excellent",…)

Wrong: =IF(B2>"249", "Excellent",…)

The logical test of the second formula will return FALSE even if the value in B2 is greater than 249. Why? Because 249 is a number and "249" is a numeric string, which are two different things.

Add spaces or line breaks to make nested IFs easier to read

When building a formula with multiple nested IF levels, you can make the formula's logic clearer by separating different IF functions with spaces or line breaks. Excel doesn't care about extra spacing in a formula, so you may not worry about mangling it.

To move a certain part of the formula to the next line, just click where you want to insert a line break, and press Alt + Enter. Then, expand the formula bar as much as needed and you will see that your nested IF formula has become much easier to understand.
Add line breaks to improve the readability of nested IFs.

Alternatives to nested IF in Excel

To get around the limit of seven nested IF functions in Excel 2003 and older versions and to make your formulas more compact and fast, consider using the following alternatives to nested Excel IF functions.

  1. To test multiple conditions and return different values based on the results of those tests, you can use the CHOOSE function instead of nested IFs.
  2. Build a reference table and a use VLOOKUP with approximate match as shown in this example: VLOOKUP instead of nested IF in Excel.
  3. Use IF with logical functions OR / AND, as demonstrated in the these examples.
  4. Use an array formula like shown in this example.
  5. Combine multiple IF statements by using the CONCATENATE function or the concatenate operator (&). A formula example can be found here.
  6. For experienced Excel users, the best alternative to using multiple nested IF functions might be creating a custom worksheet function using VBA.

This is how you use an If formula in Excel with multiple conditions. I thank you for reading and hope to see you on our blog next week.

Practice workbook for download

Nested If Excel statements (.xlsx file)

649 comments

  1. HI,
    I AM USING IF FORMULA FOR GRIDING I.E
    =IF(K6>=85,"A",IF(K6>=65,"B",IF(K6>=49,"C",IF(K6>=1,"F","N/A")))).
    BUT WHENEVER I WRITE SOME TXT LIKE ABSENT OR SYMBOL LIKE "-",THEN CELL CONTAING FORMULA SHOW IST CONDITION AND MARK IT AS "A".
    CAN SOMEONE HELP ME IN THIS MATTER

    • Faiq:
      Where do you write this text?

      • IN CELL (K6).IF SOME ABSENT AND I WRITE ABSENT OR "-" INSTEAD OF SECURING MARKS,THEN SAID FORMULA GARDE HIM AS IST CONDITION OF FORMULA MEANS GRADE HIM AS "A"

  2. Hi Sir,

    I need to write values in multiple columns with single condition using IF Statement. like...

    If(C1=10 then C2=20 AND C3=30 AND C4=40 else C2=70 AND C3=80 AND C4=90)

    how to write general formula for the above

  3. Hi Sir,

    I need to write values in multiple columns with single condition using IF Statement. like...

    If(C1=10 then C2=20 AND C3=30 AND C4=40 else C2=70 AND C3=80 AND C4=90)

    how to write general formula for the above

  4. how to apply if condition when value is in negative/below zero or value is above zero and we need the value either in zero or positive for example
    some time, while calculating income tax after saving the taxable income comes in negative we need the zero instead of negative value and if the value is in positive we need that positive value
    please explain how?

  5. Hello,

    Thanks for a very helpful knowledge. I'm stuck with this assignment for hours trying to figure out the formula. Wish u guys can help. I have set of data that needed to put into group. This is how it goes.

    A B C D E
    Item Description From To Category
    1 Cat Fish 1/2011 12/2012 Healthy

    2 Cat Fish 1/2012 12/2013 Healthy

    3 Cat Rice 1/2013 12/2013 Unhealthy

    4 Cat Fish 1/2014 12/2014 Healthy

    Based on the combination of items (Cat) and description (Fish & Rice), I can determine the category (healthy of unhealthy). My objective is to reduce the line item as to combine the range, (period from and to) since the line item 1 & 2 can be combine together from 1/2011 to 12/2013 since it goes tho the same category (Healthy).

    A B C D E
    Item Description From To Category

    1 Cat Fish 1/2011 12/2013 Healthy

    2 Cat Rice 1/2013 12/2013 Unhealthy

    3 Cat Fish 1/2014 12/2014 Healthy

    This is how I would like the end result would be. You guys have any idea how to formulate this?

    • Sorry, this is how the range should be:

      Upper:
      A B C D E
      Item Description From To Category
      1 Cat Fish 1/2011 12/2012 Healthy

      2 Cat Fish 1/2013 12/2013 Healthy

      3 Cat Rice 1/2014 12/2014 Unhealthy

      4 Cat Fish 1/2015 12/2015 Healthy

      Lower:

      A B C D E
      Item Description From To Category

      1 Cat Fish 1/2011 12/2013 Healthy

      2 Cat Rice 1/2014 12/2014 Unhealthy

      3 Cat Fish 1/2015 12/2015 Healthy

  6. Hello,

    I am designing cash advance request form for employee/ Contractor, where I have preference data like
    Requester: employee or contractor (I use Data validation function here)
    Amount: $XXX (we have rules of approval of this request on base of $ amount)
    Rules - if $XXX 3000,Finance approve)

    How I can use if function / any other excel formula so can get correct result on Approval's field?

  7. Trying to do a formula. If O10+L11+M11 is greater than 40 this cell equals 40. If O10+L11+M11 is less than 40 us that sum.

    • A simple method to accomplish what you want is to sum O10+L11+M11 in say cell N11 by entering in N11 =SUM(O10+L11+M11). Then in say cell P11 enter =IF(N11>=40,40,N11). This means that if N11 is equal to or greater than 40 display 40 otherwise display the number in N11.

  8. Hi say i have cells
    a - with different dollar amounts
    b - with either L2, L3, L4
    c - with Either anything from the Lists Below
    c.1 These can be clustered to rename the table as "LPF"
    Late Payment Fee
    LPF's info
    Late Payment Waiver Fee
    c.2 These can be clustered to rename the table as "NLPF"
    Customer Satisfaction
    CSAT Credit
    Nest Waiver Fee

    The Logic are :
    1. If there's no amount in cell "A" then it's "not applicable"
    2.a If cell "B" contains L4
    there are 2 conditions/logic
    a. If cell "B" contains "L4", cell "A" contains <-25 and cell "C"
    says that it's part of the "NLPF" list, then it shows "EXCEEDED"
    if not then it shows "NOT EXCEEDED"
    b. If cell "B" contains "L4", cell "A" contains <-50 and cell "C"
    says that it's part of the "LPF" list, then it shows "EXCEEDED"
    If not then it shows "NOT EXCEEDED"
    2.b If cell "B" contains L3, cell "A" contains <-100, then it shows
    "EXCEEDED", if not then it shows "NOT EXCEEDED"
    2.c If cell "B" contains L2, cell "A" contains <-300, then it shows
    "EXCEEDED", if not then it shows "NOT EXCEEDED"

    I already have the formula if cell "B" just have one condition/logic if it contains "L4" the thing is that it should contain 2 conditions plus it should consider the one written in cell "C". I'm finding it difficult to incorporate in my formula. Knowing that i also clustered the data in cell "C" into 2 groups.

    Can you help me regarding this?

    • =IF(A1>=0,"Not Applicable",(IF(B1="Not Applicable","Not Applicable",(IF(AND(B1="L4",A1<-25),"Exceeded",(IF(AND(B1="L3",A1<-100),"Exceeded",(IF(AND(B1="L2",A1<-300),"Exceeded",(IF(AND(B1="L1",A1<-300),"Exceeded","Note Exceeded")))))))))))

      This is my original formula

  9. Hi Team,

    Greetings
    can you please suggest me how to calculate second largest number among three numbers in 3 cells with only nested if

  10. HI Hopefully you can help me with this formula I am trying to create a new sales order form and need to for example have a list of products in one cell and according to what item is selected then the appropriate cost will come up in another cell eg: list in h22 = valley then j22=$5 if h22=hip
    hip j22=$10 if h22=gable
    gable etc.
    if need to be able to enter apx 25-30 values in the first cell (h in this example) and 15-20 in the second cell (j in this example)some of the items on the list in h will have the same value in J

    in the past my sales orders have had a page to 2 pages of rows for selecting various items and the # of items and a price and total cost for that row then all the row totals are added and taxed at the end this is fine except no one can tell what they've bought because it prints the entire sheet with all rows whether anything was selected on a row or not. if there is a way to have it consolidate and print only the pertinent rows where something was selected that would be great also hope this makes a little sense any questions please ask. hoping you can help Mark

  11. Greeting,
    I am calculating staff mileage claim every month.
    I want to split the mileage by stage below.
    Perhaps you could help me how to calculate them if :-

    Total mileage claimable is 667.55km
    1st km to 100km @ $0.50/km = 100km
    101km to 300km @ $0.45/km = 300km
    301km & above @ $0.40/km = 267.55km

    Thank you in advance

  12. I have multiple conditions like if(and(B1<1,B2<6), "Not Eligible" elseif B2<7 then "A",b2<8 "B", b2<10 "C", if(and (B1<2,B2<7),"D",if(b2<8,"E",if(b2<10,"F", if(and(B1<3,B2<7),"G",if(b2<8,"H","I"))))).

    How can i make if statement where i need to check multiple conditions.

  13. Greeting,
    I'm in kind request of your assistance,
    I am working with stock which i normally issue out weekly.
    i have different columns, opening balance, quantity received, quantity issued, closing balance among others. you realise i have a formula in the 'closing balance' column that automatically calculates; (=opening+received-closing). i have another column 'number of days out of stock'. this column includes the number of days for which the item had stocked out. example: if the i opened with 30 items on 1st march, i received 20 on 10th, issue out all the 50 on 21st then days out of stock is 31-21=10 if more is received on 25th then days out of stock will become 25-21=4.
    i want a formula that will automatically read when the 'current stock' column becomes zero and then subtracts to return the days out of stock.
    (i dont mind if the formula i am looking for assumes all months have 30 days)
    thank you in advance

  14. This is probably impossible, but I have 2 possible cost bases which generate rates of return. I need a conditional statement that says, if cost base is 1, then return is x%. If I set cost base to 2, the number in the cost base 1 result cell remains at x% - ie, I do not want it to report "FALSE"
    A B
    1 Cost base = 1, result = 15%
    2 Cost base = 2, result = 20% but cell B1 remains at 15%

    At the moment I have to copy and paste the results as values, but hope to shortcut this.

  15. Hi there,

    I'm trying to check multiple keywords and return if they feature A, B, C.

    =IF(ISNUMBER(SEARCH("sale",A:A)),"Buyers","false")

    I can't seem to extend this formula to nest multiple IFs. Any idea what I'm doing wrong, this is my attempt to extend the formula:

    =IF(ISNUMBER(SEARCH("sale",A:A)),"Buyers","false",IF(ISNUMBER(SEARCH("rent",A:A)),"Renters,""))

    thanks!

  16. if I would like to return an amount, that must meet 2 requirements/conditions form 2 other cell, how do I do that.

  17. ABCD 563 443 CLOSED
    563 443 #VALUE!
    ABCD 563 443 CLOSED
    ABCD 563 443 CLOSED
    ABCD 563 443 CLOSED
    OPEN will not show
    OPEN will not show

    If column A1>1,"open","" will show in G1"open" or blank

    but IF(AND(B1>1,C1>1,"closed","", will show in G1 "closed" or blank

  18. I am trying to build a formula to tell me if an employee has exceeded their earned vacation balance cap. The maximum caps differ depending on their years of service. Employees with 0 to 5 years (or less than 10400 seniority hours) have a cap of 120 hours; employees with 6 to 10 years (more than 10400 but less than 20800 seniority hours) have a cap of 180, and employees with 11+ years (more than or equal to 20800 seniority hours) have a cap of 240. Can anyone help me build a formula to check the balance cap based on years of service or seniority hours? I was able to create an IF formula to determine the amount of vacation time earned each pay period based on seniority, but the formula for the cap is stumping me.

  19. Condition
    1) If employee Basic salary is less than 40% of his total salary than his basic salary should become 40%
    2) If Employee salary is more than 40% , his basic salary should neither increase or decrease but should not go below 40% of his total salary any given point of time

  20. Hi!
    I'm trying to create a macro that will look at 2 cells validate if they agree if so, deliver the variance of the cells next to it to a specific cell, if it does not agree deliver the value of 0 in the these cells. then continue on to the cell below and do the same thing. I have a group of cell that have values and some days there are 7 and other days there may be just 4 but i need to ensure i am validating all everything. It has been sometime since I've done anything in VB.when i run it i get a compile error of Else without If. Hope this all makes sense. Below was what is used as my code. thank you!

    If B6 = B20 Then I6 = C6 - C20 & J6 = D6 - D20
    ElseIf B6 B20 Then I6 = "0" & J6 = "0"
    If B7 = B21 Then I7 = C7 - C21 & J7 = D7 - D21
    ElseIf B7 B21 Then I7 = "0" & J7 = "0"
    If B8 = B22 Then I8 = C8 - C22 & J8 = D8 - D22
    ElseIf B8 B22 Then I8 = "0" & J8 = "0"
    If B9 = B23 Then I9 = C9 - C23 & J9 = D9 - D23
    ElseIf B9 B23 Then I9 = "0" & J9 = "0"
    If B10 = B24 Then I10 = C10 - C24 & J10 = D10 - D24
    ElseIf B10 B24 Then I10 = "0" & J10 = "0"
    If B11 = B25 Then I11 = C11 - C25 & J11 = D11 - D25
    ElseIf B11 B25 Then I11 = "0" & J11 = "0"
    If B12 = B26 Then I12 = C12 - C26 & J12 = D12 - D26
    ElseIf B12 B26 Then I12 = "0" & J12 = "0"
    If B13 = B27 Then I13 = C13 - C27 & J13 = D13 - D27
    ElseIf B13 B27 Then I13 = "0" & J13 = "0"
    End If

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