The IF function is a powerful tool that can be used to test whether a condition is true or false. The IF function can be used to test for the existence of a certain value, the value of a certain variable, or the value of a certain range. To use the IF function in Microsoft Excel, you first need to create an equation using the = symbol and the number you want to test for. For example, if you want to test whether a number is in a certain range, you would use the =IF(number in range), where number in range is either 1 through 10 or 11 through 20. Next, you need to create an equation using parentheses and the condition you want to test for. For example, if you want to test whether all numbers between 1 and 10 are within the given range, you would use (1-10) as your condition. Finally, you need to use the IF function within your equation to perform your testing. For example, if (1-10) is true and (11-20) is false, then (1-10) will be less than (11-20).
Whether you’re grading exams or simply trying to make sense of a spreadsheet full of data, Microsoft Excel’s IF function can help. You can also use an IF function inside of another IF function to run deeper tests, too. We’ll show you how.
What Can You Do with Excel’s IF Function?
Put simply, you can use the IF function to retrieve a pre-specified result based on whether the function gets a TRUE or FALSE value.
For example, if you have a score sheet, you can make it so your cells say PASS if someone has scored 60 or higher, or say FAIL if the score is 59 or lower. You can use a nested IF to even assign grades, like an A for someone with a score of 90 or higher.
How to Write an IF Statement in Excel
To write an IF statement in Excel, all you have to do is type the function and specify what results to retrieve when the condition is TRUE and FALSE.
RELATED: How to Use Conditional Formatting to Find Duplicate Data in Excel
Start by launching your spreadsheet with Microsoft Excel. Then, click the cell in which you want to use the function.
In the following example, we’ll use the IF function to say Pass if the obtained score is 60 or higher and Fail if the score is 59 or lower.
We’ll select the D2 cell where we want to display the result.
In the D2 cell, we’ll enter the following function and press Enter.
In the selected cell, you’ll see the result depending on the value in the C2 cell.
To copy the function for all your records, from the bottom-right corner of the D2 cell, drag downwards to cover all your records.
And that’s it.
Modify the IF function in whatever way you want and you’ll get the desired result.
Use the Nested IF Function in Excel
A nested IF is an IF function inside of another IF function. You use this when you want to run another logical test after the first one.
We’ll use the following dataset to demonstrate this function:
In this dataset, depending on the scores, the following results will be displayed:
If the score is 90 or higher: A If the score is between 80 and 89: B If the score is between 70 and 79: C If the score is between 60 and 69: D If the score is between 0 and 59: F
We’ll select the D2 cell where we want to display the result, and then enter the following nested IF function and press Enter:
You’ll see the result in your selected cell.
You can copy the function for all your records by dragging downwards from the D2 cell’s bottom-right corner.
And you’re set.
Excel’s IF function is an excellent way to run various logical tests. You can use it to specify multiple conditions and display the results accordingly.
While you’re at it, check out other Excel logical functions that can be useful in your work.
RELATED: How to Use Logical Functions in Excel: IF, AND, OR, XOR, NOT