True or false, IF provides the answer

Today’s post is brought to you by Frederique Klitgaard. Frederique is a writer on Office.com

It’s easy to understand why the IF function appears in the top 10 list of popular Excel functions. It’s a versatile function that can be used for all sorts of tasks.

For example, this function can save you a lot of time when you need to grade a stack of papers. It quickly turns a long list of test scores into grades without having to do any of the math. It can also instantly determine who passed or failed.

I don’t ever grade papers but I’ll use this example to show you the effectiveness of this function. Let’s start by having a look at the syntax that this function uses to determine that a condition is true or false.

IF(logical_test, [value_if_true], [value_if_false])

The first argument, logical_test, is the required value or expression that will be evaluated to true or false. Expressions use comparison operators, such as equal to (=) or greater than (>), for example A10=100. For a list of comparison operators, see Calculation operators and precedence.

The other two arguments, value_if_true and value_if_false, are optional arguments (as indicated by the square brackets in the syntax). When these arguments are used in the formula, they’ll return the value that you want to be displayed when the logical_test argument evaluates to true or false.

I’ll apply this syntax to the following list of test scores.

Student

Test Score

Result

Grade

Student 1

35

Student 2

67

Student 3

88

Student 4

70

Student 5

95

To determine who passed or failed the test, I want the formula to return the following results:

Test score

Result

Greater than or equal to 70

Passed

Less than 70

Failed

In the first cell of the Result column, cell C2, I’ll enter the following formula:

IF(B2>=70, “Passed”, “Failed”)

To turn the list of test scores into grades, I can go a step further and embed additional IF functions as formula arguments, often referred to as nesting. You can nest up to 64 IF functions as value_if_true and value_if_false arguments.

I want the formula to return the grades as follows:

Test score

Grade

Greater than 89

A

From 80 to 89

B

From 70 to 79

C

From 60 to 69

D

Less than 60

F

Based on these conditions, the nested formula I’ll enter in the first cell of the Grade column, cell D2, will then look like this:

IF(B2>89, “A”, IF(B2>79, “B”, IF(B2>69, “C”, IF(B2>59, “D”, “F”))))

Notice that I’ve nested three other IF functions to calculate the grades. The last argument doesn’t need the IF function; it automatically displays an F for numbers that have not been accounted for in the nested IF functions. I’ve used the IF function four times, so I’ll need to include four ending parentheses in the formula.

Student

Test Score

Result

Grade

Student 1

35

Failed

F

Student 2

67

Failed

D

Student 3

88

Passed

B

Student 4

70

Passed

C

Student 5

95

Passed

A

Because I used a table format, the formula is automatically applied to all test scores. If that were not the case, however, I would just fill the formula down to the other cells in the column to get my list of grades.

That’s all there is to it. I’m ready to get my rubber stamp and grade away!

I hope that the examples I used will help you become familiar with this function. For additional information and other examples, please see our function reference article, IF function.