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)

650 comments

  1. hello sir. i hav a problem and unable to shortout.

    can i use if condition for sellected range of coloumn ..

    i.e.
    IF (A1=(B1:B8), "true","False")

    it is not corretct because the range is not accepted by if condition.
    how can i do this
    is there any other method to resolve this

    • Try this.
      =If(A1=SUM(B1:B8),"True","False")

  2. Need help for the following:

    I have % age values in a table according to each process weight-age.The start process "A" has 2% wtage, Process "B" has 25% wtage and so on till Delivery process "G" indicating 100% as %age of work comppleted.

    The Problem
    My excel has each tabs for respective process and a column as "completed date"I have a summary tab for Areawise status in which only the last completed process(ie completed date) percentage should be displayed.

    Any help would be appreciated.
    Thanks

  3. Looking for help. I have a list of zipcodes. I need a formula that says "TRUE" in the cell if the zipcode is one on the list. "FALSE" if not. Zipcodes for "TRUE" below.
    98002
    98003
    98007
    98023
    98030
    98031
    98032
    98047
    98055
    98056
    98057
    98101
    98102
    98104
    98106
    98107
    98108
    98109
    98118
    98121
    98122
    98125
    98126
    98133
    98144
    98146
    98148
    98168
    98178
    98188
    98198

    My normal If/Than does not seem to do the trick?

    • Your best bet is to create a table as your datasource of zipcodes and then use the VLookUp to compare the zip codes vs what is in your table.

      =If(Vlookup(yourzipcodecellhere,Table,1,0)=yourzipcodecellhere,)

  4. Hi, I have a formula as follows: =IF((B2="N")*AND(ISNUMBER(I2),I2>=0,I2<=6000),LOOKUP(I2,{0,996,1996,2996,3996,4996,5996},{" ","$50.00","$100.00","$150.00","200.00","250.00","300.00"}),"-")

    This works fine when B2=N, but I want the same ISNUMBER formula to run if B2 also = L. I can't figure out how to include both "N" and "L" in the same formula.

    Any help appreciated!

  5. Hi

    I've been trying to use nested formula to return a specific cost if an item is referred to in one column. Do you know why it might be returning my value as false (ie blank) if I am using the following formula just because the criteria isn't contained within the first bracket? For some reason if the first bracket is true it is fine but anything else it just shows as blank?

    =CONCATENATE(IF(C5="Napoleon","£1000",""),IF(C5="Sussex","£2000",""),IF(C5="Townhouse","£3000 ",""),IF(C5="GO","£4000",""))

    • Actually managed to solve the one above but was wondering if it would be possible to do the formula

      =IF(D2="PM",(IF(C2="Napoleon","£5000",""),IF(C2="Sussex","£3500",""),IF(C2="Townhouse","£2500 ",""),IF(C2="GO","N/A",""),IF(C2="DDR","COST","")),(IF(C2="Napoleon","£2500",""),IF(C2="Sussex","£2500",""),IF(C2="Townhouse","£1500 ",""),IF(C2="GO","N/A",""),IF(C2="DDR","COST","")))

      Where I'm trying to say if D2= PM "Value if true as a nested if formula", "value if false as a nested if formula"

  6. I need a formula in excel for the below.
    A1 contains some value and B1 contains Text A, B, C, D
    Formula should do the following:
    if B1 is A then check the following A1 is greater than 5 but less than 10 it should return 10, if A1 is greater than 10 should return value in A1, if A1 is less than 5 should return 5, if B1 is B then check the following A1 is greater than 5 but less than 10 it should return 8, if A1 is greater than 10 should return value in A1, if A1 is less than 5 should return 5

    How can you put the formulae in excel? Can any body explain

    • A...fine
      B...fine
      What if C or D?

      If you want to do nothing when B1 is C or D, then formula yo use is:

      =IF(B4="A",IF(AND(A4>5,A4<10),10,IF(A4#10,A4,IF(A4<5,5,"N/A"))),IF(B4="B",IF(AND(A4#5,A4<10),8,IF(A4#10,A4,IF(A4<5,5,"N/A")))))

      Replace # with "greater" sign.

      If B1 contain C or D, then the result is FALSE.

  7. Hi Dear, I m user of excel I have a data in row A and row B .I want to find what data are same in both the row.please let me know the formula for the same

    • =A1=B1
      That is. The result into cell C1 will be "TRUE" or "FALSE"
      True if A1=B1, false if A1 not equal B1.

      Or this formula:
      =IF(A1=B1,"EQUAL","")
      It is show "EQUAL" if A1=B1, and "" (nothing) if A1 not equal B1.

  8. Bill says:
    February 1, 2017 at 7:34 am
    3 Range : Time, Value A, Value B

    Triger : “>=7”

    condition : between A and B, who reach 7 first in period of time 1 to 6, then win.

    *Eq 1 : in a period of time show by range Time 1 to 6, A hit 7 first before B. then, “A WIN“

    Time | A | B | A WIN

    1 | 1 | 2 |

    2 | 5 | 2 |

    3 | 7 | 4 |

    4 | 5 | 5 |

    5 | 4 | 6 |

    6 | 3 | 7 |

    *Eq 2 : in a period of time show by range Time 1 to 6, B hit 7 first before A. then, “B WIN“

    Time | A | B | B WIN

    1 | 1 | 2 |

    2 | 5 | 7 |

    3 | 7 | 4 |

    4 | 5 | 5 |

    5 | 4 | 6 |

    6 | 3 | 2 |

    Please help me how to make this formula, its been 3 days im trying but i still cant figure it out,

    thanks in advance.

    By: Bill

    • =IF(AND(A2>=1,A2=7),"Awin",IF(AND(A2>=1,A2=7),"Bwin",""))

      For search first instance of Awin or Bwin try VLOOKUP formula.
      If you have time value (not 1 to 6 values) use TIMEVALUE formula.

    • =IF(B2=7,"A",IF(C2=7,"B","NIL")) formula for ist query A win same way for the next one too have a Nice day

  9. hi again.
    mr remind the formula you gave doesn't work.

    please give me the true formula.
    this is the problem.

    if F15 is within 0.26-0.75 and H15 is above 0.20 the value returns to "retained"

    if F15 is within 0.26-0.75 and H15 is below 0.20 the value returns to "revised"

    if F15 is not within 0.26-0.75 and H15 is above 0.20 the value returns to "revised"

    if F15 is not within 0.26-0.75 and H15 is below 0.20 the value returns to "rejected"

    I will be glad to your right response. thank u.

    • Julius,
      Please send me a sample to help you.
      remindfwd[at]gmail[dot]com
      I solved your formula, but is better to comunicate by e-mail.

    • =IF(AND(0.26<F15<0.75,H15#0.2),"retained",IF(OR(AND(0.26<F15<0.75,H15<0.2),AND(0.26#F15#0.75,H15#0.2)),"revised",IF(AND(0.26#F15#0.75,H15<0.2),"rejected","N/A")))

      Replace # sign with "greater" sign.

      Is working?

  10. Hi,

    First of all I would like to congratulate you for this wonderful site and all your efforts for making using excel much more easier than it used to be. I had started working on excel in my teens and learned a lot but you all are able to surprise me with the new ways you mentioned to tackle the issues or the innovative uses of formulas.

    now coming to the point, i am having difficulty in analysing some data for my report.i have a report which states a specific purchase order code with the quantity in the very next column but the supply is being received in parts. so the system application plots all the receipt against the very same order. but when the report of the same is exported in excel, it repeats the order and quantity against every receipt thus no general formula could be used to just subtract the receipt form order and the data spread over thousands of rows so manual calculation is impossible.

    for example:
    Column A states order no XX/1*12
    Column B states Quantity demanded to be 10000.00
    Column C states the receipts in the tune of 300,1500,2500,700 & 4500.
    Thus the balance should be 500 but since the values of Column A and B repeats, simple subtraction comes as 9700, 8500, 7500, 9300 & 5500 respectively for the balance quantity.

    Can you suggest any possible formula or a set of formulas to derive the balance quantity after considering every aspect.

    • Try VLOOKUP formula in addition with others.
      If you send to me a sample from your report (not real names or prices or quantities) I will try to hel you.
      my e-mail remindfwd[at]gmail[dot]com

  11. Sorry 2!

    =IF(AND(F15>=0.26,F15<=0.75,H15>=0.2),"retained",IF(AND(F15<=0.26,F15>=0.75,H15 sign (First H15 and forth F15)

    • thanks a lot God bless (^_^)

  12. hi. someone help me with my item analysis please.

    when f15 is within 0.26-0.75 and h15 is above 0.20 the value returns to "retained"

    when f15 is not within 0.26-0.75 and h15 is below 0.20 the value returns to rejected

    • In the cell G17 (or where you want) insert this formula:

      =IF(AND(F15>=0.26,F15=0.2),"retained",IF(AND(F15=0.75,H15<=0.2),"rejected","N/A"))

      If you want to change N/A with something else, be my guest.

    • Sorry!

      =IF(AND(F15>=0.26,F15=0.2),"retained",IF(AND(F15=0.75,H15<=0.2),"rejected","N/A"))

    • O, thats is impardonable:
      The formula is:
      =IF(AND(F15>=0.26,F15<=0.75,H15#=0.2),"retained",IF(AND(F15<=0.26,F15#=0.75,H15<=0.2),"rejected","N/A"))

      Replace # with "greater" sign

  13. I have suppliers, who sell to me the same products at different prices, different lead times for those different products and different account payable dates.

    I need to make a comparison between them and make a choice on who has better terms using excel.how can I go about it?

    Thank you.

  14. Hi
    I am new in excel.
    I have question, if I have 2 columns (column a and b), each column has negative and positive value. How can I sum if the condition is "show sum of column a and b if either column a or b are negative"?

    Thank you

    • Hi Fanteri,

      Here is the formula you can use:
      =IF(OR($A1<0,$B1<0),SUM(A1,B1),"")

      It says "if either value in A1 or B1 is less than 0, then sum values in A1 and B1, otherwise show a blank cell". Copy it down the column where you enter the formula to get the results for each row.

      You can read more about OR condition in this blog post.

      I hope this helps.

  15. A B C
    12345 10
    12345 20 #NAME?
    12345 LTP 30

    IF COLUMN A same value, take column B as a return . answer should be '30'.

  16. I have more than one number in the same column and between each number there is a empty cell .. what I need is to repeat the number between each number using excel formula .. please send me the formula that will help in adding the field that are not showing between two number cause I have a big data and need to add the formula also I wanted the system to check using if in case that possible .. will Waite for your reply as soon as possible .. appreciate your assistant..

    I will be very glad if you can send me the formula in me email

    • Lets say in B1 is your value
      then in B3 =IF(LEN(B1)>0;B1;"")

  17. i have created the formula"=IF(G7=K15,L15,IF(G7=K16,L16,IF(G7=K17,L17,IF(G7=K18,L18,IF(G7=K11,L11,IF(G7=K12,L12,IF(G7=K13,L13,IF(G7=K14,L14))))))))" in ceel H9;BUT FOR MORE THAN 8 CONDITION THIS NOT WORK; WHAT TO DO SOLVE THIS PROBLEM.

    • I am not sure what you want to acomplish but usually if you need more then 3 ifs thats mean you are doing something wrong.

      also lets say K17 = K19 it will return K19 because its first if that doesent matter then use:

      =VLOOKUP(G7;K11:L18;2;0) just change your range that best serves you

      if same values are problem then:

      =IF(COUNTIF(K11:K18;G7)>1;"MORE THEN ONE";IF(COUNTIF(K11:K18;G7)<1;"NO MATCHES";VLOOKUP(G7;K11:L18;2;0)))

  18. i have prepare the formula-=IF(G7=K 14,F11,E20), =IF(G7=K15,F11,E21), =IF(G7=K16,F11,E22) incell E20 TO E22; BUT THE SUM OF THE VALUES FROM THESE FORMULA NOT DISPLAY & A MESSAGE IS DISPLAYED" careful we have found one or more circular reference in your work book that might cause your formula in correctly"

    • Hello Sunil,

      The reason why you get this error is that you are trying to get value from the same cell where you enter the formula. Please replace E20 in the formula or describe what you are trying to achieve in more detail, I'll do my best to assist you.

  19. Dear Svetlana,

    I need your help. I have a training matrix that that has different training clumns and different dates.

    for example Company Induction that will be valid for three years. Cell value is 9-Aug-16. i want to highlight it will expire after 3 years.

    if it is 9-Aug-13 it is also expire

    This goes to all training dates with different validity.

    please help me on this...thanks in advance

  20. HI Sventana,

    Thanks for another aspect of Nested if Function. Really nice and useful Information. Expecting some Detailed Article on CF,Data Validation,Offset,Index Match. Great JOB

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