How to Use the IF Function in Excel: Step-by-Step (2024)

The IF function is going to be one of the most useful functions of Excel you’ll ever come across🤩

Once you know how to write the IF function, you’ll use it almost everywhere. With the IF function, Excel tests a given condition.

And returns one value if the condition turns true and another if it turns false. More details about the IF function with many examples of the same await you in the guide below 👇

So jump straight in and take our free sample workbook along with you to practice better.

How to use the IF function in Excel

The IF function is a logical function of Excel that’ll test a supplied condition. If the condition is true, the IF function would return one value.

And if it is false, it will return another value. And by the way, both these values will be supplied by you. Let’s see this through an example 👩‍🏫

Here we have a list of some people along with their ages.

List of people and their ages

Can we use the IF function to see which of these are of the age of 50? For sure. See here:

  1. Activate a cell.
  2. Write the IF function as below:

= IF (B2=50,

Writing the IF function

For the first argument of the IF function, write in the condition to be tested 👴

We want to test if the age of each person equals 50. Ages are in column B so we have written the logical condition B2=50.

This tells Excel to test if B2 is equal to 50.

Note that we have used a logical operator (=) to specify the condition. You’d need a logical operator to specify any kind of condition.

Kasper Langmann, Microsoft Office Specialist
  1. As the next argument, write the value_if_true as below:

= IF (B2=50, “Equals 50”,

Writing the value_if_true

The value_if_true is the value that Excel would return if the logical condition turned true. It is an optional argument that you can omit ❌

For now, we are setting it to “Equals 50”.

If the value_if_true is omitted, and the logical test turns true, Excel simply returns the Boolean value “TRUE” in its place.

Kasper Langmann, Microsoft Office Specialist
  1. Next, write in the value_if_false as below:

= IF (B2=50, “Equals 50”, “Doesn’t equal 50”)

Writing the value_if_false

The value_if_false is the value that Excel would return if the logical condition turned false. It is also an optional argument that you can omit.

We have set it to ‘Doesn’t Equal 50” 🙈

Do not forget to enclose the value_if_true and value_if_false in double quotation marks. Or else would fail to recognize it as a text.

And your IF function would return the #NAME error 🤯

If the value_if_false is omitted, Excel simply returns the Boolean value “FALSE” in its place.

Kasper Langmann, Microsoft Office Specialist
  1. All good! Hit Enter.
IF function formula returns the results

The IF function evaluates if Cell B2 is equal to 50. And as that’s not the case, we get “Doesn’t equal 50” (the value_if_false) 🚩

  1. Drag and drop the same formula to the whole list.
Formula applied to the whole list

And there you get the results of the IF function for the entire list🥂

Note how Excel has supplied the value if true (Equals 50) for Cell B3 and B6 where the age is 60. Pretty simple that was!

IF and logical operators

You can take the IF function game levels ahead by using it together with logical operators.

For example, using the same dataset as above, can we readily see which people are above 50 👀

  1. Write the IF function as below:

= IF (B2>50,

The logical condition for the IF function

As we want to find the ages that are greater than 50, we are going to define a logical condition using the greater than (>) logical operator.

So we have written the condition as B2>50 (is B2 greater than 50?).

  1. Then write the value_if_true and value_if_false as below:

= IF (B2>50, “Greater than 50”, “Not greater than 50”)

Writing the true and false values

We want Excel to return the text string “Greater than 50” if the age is more than 50.

And if any age is less than 50, we want Excel to return “Not greater than 50” ✈

  1. Press Enter.
IF function returns the results

The IF function evaluates if Cell B2 is greater than 50. And we get the result “Greater than 50” in the very first cell as the age in Cell B2 is 88. (88>50) 👌

  1. Drag and drop the same formula to the whole list.
Formula applied to the whole list

Excel evaluates the whole list, and we have our results ready. You can use logical operators like that to test any logical condition.

Pro Tip!

You can use a total of 6 logical operators to write any logical test in Excel 6️⃣

  • Equal to (=)
  • Greater than (>)
  • Less than (<)
  • Greater than or equal to (>=)
  • Less than or equal to (<=)
  • Not equal to (<>)

Other IF formula examples

We’ve yet not had enough of the IF function – and there’s much more to come. Let’s see some more examples of the IF function below 🚴‍♀️

IF formula example #1

The above two examples show how you can use the IF function with numbers. But what if you want to use it with text?

You can still do that. Look into the data below.

Status of Employee duties

Some employees worked overtime, whereas others did not. Based on the overtime detail, we need to offer incentives to employees 💰

So can we readily see which employees are getting a bonus this time?

  1. Write the IF function as below:

= IF (B2=”Worked Overtime”

Text as the logical condition

As we want to find which employee did overtime, we defined the logical condition B2=” Worked Overtime”.

This way Excel will see if cell B2 contains the text value “Worked Overtime” or not.

Here’s something for you to take note of. As we have specified text in our logical condition this time, we have enclosed it in double quotation marks.

Excel would fail to test a text logical condition if the text portion is not enclosed in quotation marks 📌

Kasper Langmann, Microsoft Office Specialist
  1. Then write the value_if_true and value_in_false as below:

= IF (B2=”Worked Overtime”, “Yes”, “No”)

Writing the true and false values

For any employee who has worked overtime, Excel will return a “Yes” and vice versa.

  1. Hit Enter to run the function 🏃‍♀️
IF function runs the logical test
  1. Drag and drop the same formula to the whole list.
IF statement applied to the whole list

The IF function tests if the cells have the text value “Worked Overtime”. And for all the cells that have this value, the result is a “Yes”. And for the employees who didn’t work overtime, the result is a “No”.

Pro Tip!

Did you note that Cell B5 has the status “WORKED OVERTIME” (uppercase characters)?

However, the IF function still finds the logical test to be true, and we have the value “Yes”.

This tells that the IF function is not case-sensitive 🏆

IF formula example #2

This example is going to be an interesting one. We are going to use the IF function with dates in logical tests.

The image below shows different events scheduled on certain dates 📅

In addition to these events, there is another event planned for 03 March 2023. We will now use the IF function to see if any event clashes with the event on 03 March.

  1. Write the IF function as below:

= IF (B2=DATE(2023,03,03)

as the logical condition

We have written the logical test as B2=DATE(2023,03,03)

Excel would now test if cell B2 contains the date 03-Mar-2022 or not.

Pro Tip!

To write the logical criterion using date, we have used the DATE function that works as follows:

=DATE(year,mm,dd)

It is important to know that the logical functions of Excel cannot recognize dates. They instead consider them as text strings 😅

To use dates in the IF function, you must use the DATE function for Excel to convert the date into an understandable format.

Alternatively, you can convert the date into a serial number and then write the IF function like this:

= IF (B2=44988,

However, to know the serial number for the targeted date (like 44988 for 03 March 2023), you still need to apply the DATE function separately 🤷‍♀️

  1. Then write the value_if_true and value_if_false as below:

= IF (B2=DATE(2023,03,03), “Yes”, “No”)

 

Writing the true and false values

For events that are scheduled on 03 March 2022, Excel will return a “Yes”.

And if that’s not the case, we will get a clean “No” ❌

Interesting, right? Let’s now run the function to see the final results.

  1. Hit Enter.
IF function evaluates the corresponding value
  1. Drag and drop the same formula to the whole list.
IF formula returns the results

Seems like we would have to miss out on Event 3 and Event 5 🙅‍♂️

That’s it – Now what?

A long way we’ve come. In the guide above, we have seen how to use the basic IF function, IF function with logical operators, and with single and multiple conditions.

With this, you now know all the ins and outs of the IF function of Excel. I hope you enjoyed reading it as much as I enjoyed writing it ✍

If you found the IF function useful, must know that it only makes one function of the great Excel. This giant spreadsheet software has so much more for you to explore.

To become an Excel maestro, you must have a fine grip on Excel functions. Particularly, the key Excel functions like the VLOOKUP, SUMIF, and IF functions.

Don’t know where to start? Enroll in my 30-minute free email course that will take you through these (and many more) functions of Excel.

Other resources

Did you know? There is a successor to the IF function that can help you test multiple conditions together (and perform multiple comparisons). The IFS function.

Read our blog on the IFS function and some potential problems with the IFS function here to learn more about it.

Frequently asked questions

IF is a logical function of Excel. It tests a given condition to be logically true or false.

It allows users to specify a value to be returned if the supplied condition is true, and a value if it is false.

The IF function then evaluates the condition and returns the relevant value if it proves true or false.

The Excel IF function has the following three articles:

Logical_test (required argument) – this is the logical test to be performed.

Value_if_true (optional argument) – this is the value to be returned if the logical test is true.

Value_if_false (optional argument) – this is the value to be returned if the logical test is false.

The IF function can be used to test more complex scenarios by nesting multiple IF functions together.

For example, you can nest multiple IF functions together as follows:

 = IF (logical_condition, [value_if_true], IF (logical_condition, [value_if_true], [value_if_false])

This tells Excel to test the first IF function and return the value_if_true if it is true. And if it is false, test the second (nested) IF function.

To learn this in much more detail (with a handful of examples), read our tutorial on the Nested IF function here!