In the code above, T1-T5 represents 5 different logical tests, and R1-R5 represents 5 different results. You can see that each IF function requires it's own set of parentheses.
This article describes the Excel nested IF construction. Usually, nested IFs are used when you need to test more than one condition and return different results depending on those tests.
Testing more than one condition
If you need to test for more than one condition, then take one of several actions, depending on the result of the tests, you can nest multiple IF statements together in one formula. You'll often hear this referred to as "nested IFs".
The idea of nesting comes from embedding or "nesting" one IF function inside another
In the example shown, we are using nested IF functions to assign grades based on a score. The logic for assigning a grade goes like this:
To build up a nested IF formula that reflects this logic, we can start by testing to see if the score is below 64. If TRUE, we return "F". If FALSE, we move into the next IF function. This time, we test to see if the score is less than 73. If TRUE, we return "D". If FALSE, we move into yet another IF function. And so on.
Eventually, the formula we have in cell D5 looks like this:
You can see that it's important in this case to move in one direction, either low to high, or high to low. This allows us to return a result whenever a test returns TRUE, because we know that the previous tests have returned FALSE.
Making nested IFs easier to read
By their nature, nested IF formulas can be hard to read. If this bothers you, you can add line breaks inside the formula to "line up" the tests and results. See the video link on this page to see how it's done.
The IF function can perform a logical test and return one value for a TRUE result, and another for a FALSE result. For example, to "pass" scores above 70: =IF(A1>70,"Pass","Fail"). More than one condition can be tested by nesting IF functions....
Nesting is a powerful tool, but once you combine more than a couple IFs, the logic can start to look like spaghetti quickly :) The trick is to keep things organized. In this video, Dave shows a painless way to build a nested IF formula.
The IF function is very versatile. You can use it whenever you need to test a condition and take an action based on the result. You can even combine multiple IF statements to check multiple conditions.
Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.