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. Hi

    I wanna to add time condition with stock price
    Like
    Open Ltp Time
    223 223 9:15

    Now i need if open=ltp at 9:15 then it print good to enter else blank

    as Ltp is dynamic so i wanna to capture values at 9:15 only.

    Hope for early and quick response

    Thanks in advance

  2. I need to create an IF..AND formula for these conditions:
    calculate the total cost of the car rental (#days * cost)
    if the transaction is eligible, give a 20% discount on #days * cost
    if the transaction chose to add gas,add $65

    So the possible outcomes are:
    days * cost only
    days * cost minus discount
    days * cost plus gas
    days * cost minus discount plus gas.

    I have been banging my head for too long. I know it needs to be nested, but...

    Thank you

  3. This formula returns #VALUE.

    =IF(AND('Maint Pricing'!$B2="Flat Rate",'Monthly Calculation'!$D4="Yes"),('Maint Pricing'!$X2+'Maint Pricing'!$Q2),'Maint Pricing'!$X2), IF(AND('Maint Pricing'!$B2="Area Rate",'Monthly Calculation'!$D4="Yes"),('Maint Pricing'!$V2+'Maint Pricing'!$Q2),'Maint Pricing'!$V2)

    Can someone help me with this?

  4. Need your help with a formula.
    I need to subtract the percentage of a value based on the number of items selected.
    The percentages need to change based on the number of items selected.

    Exeample> one item costs 10 usd.
    take 1 item 0% take 2 items 15%bonus, take 3to5 items 30% bonus take 6to10 50% bonus.
    I want to be able to select the number of items in a cell, and in another cell show the value according to the number of items selected.
    Can someone help me?

  5. Hello,

    I'm bit confuse in applying "If" formula to my data, where I want to get data by applying specific condition;

    I want data like, "If Employee X has completed any Job in Task1 then he will get XYZ Units, same way, if Employee X has completed Job in Task2 than he will get ABC Units.

    So I'm bit confused what formula to use here, could you please guide me here?

    Thanks,
    Milan

  6. I am trying to set up a formula were New=New, Used_Like_New=Like New, Used_Very_Good=Very Good, Used_Good=Good, & Used_Acceptable=Acceptable.

    The formula I tried was =IF(AND(G2>=New), "New", "" & IF(AND(G2>=Used_Like_New), "Like New", "" & IF(AND(G2>=Used_Very_Good), "Very Good", "" & IF(AND(G2>=Used_Good), "Good ", "" & IF(AND(G2>=Used_Acceptable), "Acceptable", ""))))). I also tried =IF(AND(G2=New), "New", "" & IF(AND(G2=Used_Like_New), "Like New", "" & IF(AND(G2=Used_Very_Good), "Very Good", "" & IF(AND(G2=Used_Good), "Good ", "" & IF(AND(G2=Used_Acceptable), "Acceptable", ""))))).

    I have had no luck. This is my first attempt at an If formula. Can you help me out here?

    • Hi Chris,

      Here's the correct syntax:

      =IF(G2="New", "New", IF(G2="Used_Like_New", "Like New", IF(G2="Used_Very_Good", "Very Good", IF(G2="Used_Good", "Good ", IF(G2="Used_Acceptable", "Acceptable", "")))))

      • Thank you!!!

  7. Not sure why my last post didnt include my actual formula but since its not working its not a biggy :)

    • Hi Milli,

      Our blog engine occasionally mangles formulas in comments, sorry for that.

      As for your formula, please try this one:
      =IF(E3="", "", IF(E3<=1989, 1, IF(E3<=2013, 2, "")))

      If the list separator in your Regional Settings is set to semicolon, then it should be written like this:
      =IF(E3=""; ""; IF(E3<=1989; 1; IF(E3<=2013; 2; "")))

      Please note that the formula will return nothing (an empty string) if E3 is greater than 2013.

  8. Hello!
    Not sure why excel hates my If formula...
    Point is- if a cell value (let's say "E3") is missing, do nothing. if it's smaller than 1989, write 1, if its between 1990 and 2013, write 2.

    I wrote : if ((0>E3E3<2013);2))

    but its not working :-(

    Would be grateful for your advice!

    M.

  9. Hi, in column B i have date & column C other commodity and I want to calculate on basis of date can any one help.

  10. Hi, i have one question plz guide me, i have tow columns with same values, i used if I5 is less than one get H5 value, but the result is not comimg what i want
    =if(I5<1,"=H5")
    Can you help me.
    Thanks

  11. I want to convert grades in marks like for A its 5 marks, B its 4 marks , C its 3 marks, D its 2 marks and for E its 1 mark. please suggest formula.

    • If you want to substitute the grades in the same table they are arranged in, use Find and Replace.
      However, if you want to transfer the converted data to another table, try entering this simple formula:
      =70-code(A2)
      where A2 is the cell with the grade.

  12. Sir/Madam,
    I want to format a account sheet in excel. Here I need to make a account of around 25 projects. Here I create 3 columns (let’s say R1, R2,R3) only for project code, amount and the respective project’s balance amount.
    Means, firstly I will enter the project code let’s say AB01, next column I will enter the amount to be updated and last, the total balance amount must updated automatically in the last column. [r3 should update automatically]. I,e when I enter the project code, R3 should go to the cell where current balance entered of that particular project.
    If possible with anyone, can you give me the VB in excel, also the formulae code( =xxxxx, Rxx)
    R1 R2 R3
    ABO1 140 2200
    AB01 100 2100
    AB02 100 1340
    AB02 200 1140
    ABO2 140 1000
    AB01 100 2000
    AB02 100 900

    Thanks in advance.

  13. Hi,

    I have this problem with my syntax, after hit 'enter' button, no error pops up, but then, the excel only operate my 3 first condition, the remaining condition were disregard (I assumed). any chance anyone can correct my syntax?

    =IF(Q12="Done","No Action Require",IF(Q12<-5,"-5,"=-3,"0,"Due","")))))

    Thanks.

    • =IF(Q12="Done","No Action Require",IF(Q12<-5,"-5,"=-3,"0,"Due","")))))

      • I have already copy and paste my syntax, but when it posted, it does not show the full syntax?

  14. Hi there can you help me with please one?

    how to make a formula with this

    If A2 is 0-1= Current
    A2 is 1.1-2= curring
    A2 is 2.1-3= mid-range
    A2 is 3.1-4= delinquent
    A2 is 4.1 above= recovery

    Thanks in advance

  15. Guys I have a problem to solve as follows:
    Column A is weight as 1,2, 3..n & column B is rate as €1, 2,3.
    To look for a value upto 25 kg I can use vlookup. But the problem is above 25 kg the rate is calculated as follows: upto 25 kg €100 and for next 20 kg € 2 per kg and for next 40 or more €4 per kg. I want a formula by which entering a particular weight in a cell the total rate is found. Please help me with this. TIA

  16. 18.49,18.50,18.51,19.00,18.54,18.52,19.00,18.52,18.53,18.59,18.57,18.57, 18.53,18.53,19.01,18.51,18.56,18.49,18.49,18.53,18.49,18.50

    I can find duplicate values but cant replace it with another value.

    can u pls help me on this

  17. or better yet lets put it this way:

    "if a1=1 and b1=6 then 7 otherwise 14 and if a1=1 and b1=7 then 8 otherwise 16 and if a1=1 and b1=8 then 9 otherwise 18."

    this is the formula that I'm trying to use:
    =if((and(a1=1,b1=6)),”7”,”14”),if((and(a1=1,b1=7)),”8”,”16”),if((and(a1=1,b1=8)),”9”,18”)))

  18. Hi, I need help in making multiple arguments using if function. I would like to make something like this IF(A1=6 AND B2=SS THEN 7 OTHERWISE 14, AND IF A1=7 AND B2=SS THEN 8 OTHERWISE 16 AND IF A1=8 AND B2=SS THEN 9 OTHERWISE 18)

  19. =IF(D3<VALUE("0:05"),0,IF(D3<VALUE("0:15"),1,IF(D3<VALUE("0:30"),2,IF(D3<VALUE("0:60"),3,IF(D3<VALUE("4:00"),4,15)))))
    I have tried the above formula and got the following:
    Assign Points Based on Late Time
    Start Actual Late By Late Points
    8:00:00 AM 7:55:00 AM 0:05 15.00
    8:00:00 AM 8:05:00 AM 0:05 15.00
    8:00:00 AM 8:07:00 AM 0:07 15.00
    8:00:00 AM 8:35:00 AM 0:35 15.00
    8:00:00 AM 9:35:00 AM 1:35 15.00
    8:00:00 AM 12:15:00 PM 4:15 15.00
    8:00:00 AM 2:45:00 PM 6:45 15.00
    8:00:00 AM 10:00:00 AM 2:00 15.00
    8:00:00 AM 9:20:00 AM 1:20 15.00
    8:00:00 AM 7:45:00 AM 0:15 15.00
    8:00:00 AM 12:20:00 PM 4:20 15.00
    8:00:00 AM 7:15:00 AM 0:45 15.00

    what is wrong with this?

  20. Hi

    I have 1,2,3,4,5 numbers in 5 different cells and i need to put one number in cell at one time, if i put 2 different number i need to mark with message, pls help me in this regard

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