Quick Links

Key Takeaways

The IF function returns different values depending on whether a condition is true or false. Use it in the form =IF(Condition,True,False). For example, =IF(C2>=60,"Pass","Fail") will return "Pass" if the value in C2 is equal to or over 60 and "Fail" if the value is under 60.

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.

Choose a cell.

In the D2 cell, we'll enter the following function and press Enter.

=IF(C2>=60,"Pass","Fail")

In the selected cell, you'll see the result depending on the value in the C2 cell.

Result of Excel's IF function.

To copy the function for all your records, from the bottom-right corner of the D2 cell, drag downwards to cover all your records.

Result of Excel's IF function for all 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:

Dataset for Excel's nested IF 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:

=IF(C2>=90,"A",IF(C2>=80,"B",IF(C2>=70,"C",IF(C2>=60,"D",IF(C2>=0,"F")))))

You'll see the result in your selected cell.

Result of Excel's nested IF function.

You can copy the function for all your records by dragging downwards from the D2 cell's bottom-right corner.

Result of Excel's nested IF function for all records.

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.

Mastering Excel Functions

Functions

AVERAGE · CONCATENATE · COUNT · COUNTIF · DATEDIF · FILTER · FREQUENCY · FV · HYPERLINK · IF · IFS · IMAGE · INDEX · IS · LEN · MATCH ·MEDIAN · RAND · ROUND · RRI · SORT · SQRT · SUBSTITUTE · SUBTOTAL · SUM · SUMIF · TODAY · TRIM · TRUNC · VLOOKUP · WEEKDAY · XLOOKUP · YEAR

Types

Basic · Budgeting · Data Entry · Logical · Text · Time and Date

Explained

Copying Formulas · Evaluating Formulas · Finding Functions · Fixing Formula Errors · Functions vs Formulas · Comparing Lookup Functions · Locking Formulas · Structuring Formulas · Translating Formulas