Skip to main content

How to use the Excel IF function

The IF function is one of the most commonly used functions in Microsoft Excel. With it, you can test a value to see if it meets criteria. If it does, then display one result and if it doesn’t, then display a different result. This is basically an If, Then scenario.

You can use the IF function with text, numbers, or any combination, giving you flexibility. Here, we’ll explain the syntax for the formula and arguments followed by a few examples to help you use the function for your own data.

Difficulty

Moderate

Duration

15 minutes

What You Need

  • Microsoft Excel

The IF function formula syntax

The IF function has a simple syntax with only three arguments, making it easy to use. The syntax is IF(test, if_true, if_false) where only the first two arguments are required.

Test: This is the value you want to test and the criteria you want to use. Since you're comparing data, you can use a cell reference with the condition to compare it to.

If_true: This is the result to display if the value meets the criteria. This can be text or a number.

If_false: This is the result to display if the value does not meet the criteria and can also be text or a number.

Now that you have the syntax and arguments for the formula, let’s look at some examples for how to use the IF function in Excel.

Use IF with text

You can use text for the test as well as the results. Be sure to include the text within quotation marks.

For this example, we have student grades. We want to display Fail if the grade is an F and Pass for any other grade. The grade is located in cell B2.

Step 1: Select the cell where you want to display the result. This is the cell where you’ll enter the formula.

Step 2: Type the formula into the cell, replacing the arguments with your own: =IF(B2=”F”,”Fail”,”Pass”).

To break down the formula, if the text in cell B2 is (equals) an F, then display Fail. If it’s not an F, display Pass.

IF function using text for the test and results.
Image used with permission by copyright holder

Step 3: Press Enter or Return.

You’ll then see the result in your cell. If you want to use the same formula for additional cells, use the fill handle to drag the formula to the other cells.

Dragging to copy the IF function formula in Excel.
Image used with permission by copyright holder

Use IF with numbers

It’s just as easy to use the IF function to test numbers as text. With numbers, you do not have to place the values within quotation marks.

For this example, we have a product order. If the order subtotal is greater than or equal to $100, the customer gets free shipping. If it’s less than $100, they pay $49.99 for shipping. The subtotal is located in cell D6.

Step 1: Select the cell where you want to display the result to enter the formula.

Step 2: Type the formula into the cell and replace the arguments with yours: =IF(D6>=100,0,49.99).

To break down this formula, if the value in cell D6 is greater than or equal to 100, then display nothing (zero). If it’s not, then display 49.99.

IF function using numbers for the test and results.
Image used with permission by copyright holder

Step 3: Press Enter or Return.

You’ll then see your result in the cell with the formula. To give it a test, you can change the subtotal to be sure that the shipping amount changes accordingly.

IF function using numbers for the test and results.
Image used with permission by copyright holder

Use IF with text and numbers

You can use text or a number for the test and text or a number for each result. Again, this gives you great flexibility with the IF function in Excel.

For this next example, we’ll go back to our student grade sheet, but this time we’ll use the numeric grade for the test. The numeric grade is in cell C2 and we want to display Pass for grades above 1.0 and Fail for grades below 1.0.

Step 1: Select the cell where you want to display the result and enter the formula.

Step 2: Type the formula into the cell, replacing the arguments with yours: =IF(C2>1,”Pass”,”Fail”).

To break this one down, if the value in cell C2 is greater than 1, display Pass. If it’s not, display Fail.

IF function using a number for the test and text for the results.
Image used with permission by copyright holder

Step 3: Press Enter or Return.

Like the example directly above, you can test your formula by changing a grade to confirm that the correct result displays, or copy the formula down to the other cells to check the other grades.

Dragging to copy the IF function formula in Excel.
Image used with permission by copyright holder

Use IF with calculations

Another way to use the IF function is with a calculation such as addition, subtraction, or multiplication. For instance, if our value meets the condition, we’ll perform a calculation. If it doesn’t, then we’ll do something else.

Let’s use our product order and shipping fee example. We’ll automatically add the fee if the subtotal is less than $100. If it’s $100 or more, we’ll simply display that subtotal because the shipping is free. The subtotal is in cell D6.

Step 1: Select the cell where you want to display the result and enter the formula.

Step 2: Type the formula into the cell and replace the arguments with your own: =IF(D6>=100,D6,D6+49.99).

Breaking down this formula, if the value in cell D6 is greater than or equal to 100, simply display the value in cell D6. If it’s not, then add 49.99 to the value in cell D6.

IF function using a number for the test and calculation for the results.
Image used with permission by copyright holder

Step 3: Press Enter or Return.

Like the other formulas above, you can quickly test your formula to be sure the result changes for different amounts.

IF function using a number for the test and calculation for the results.
Image used with permission by copyright holder

Now that you know how to use the IF function in Excel, take advantage of this useful tool to test values of your own or those you pull in from a PDF file.

For more, check out how to merge and unmerge cells or how to use concatenate to combine data in Excel.

Editors' Recommendations

Sandy Writtenhouse
Sandy has been writing about technology since 2012. Her work has appeared on How-To Geek, Lifewire, MakeUseOf, iDownloadBlog…
How to find your Windows 11 product key
EcoFlow River 2 Pro used indoors to power office computer and equipment.

Your Windows 11 product key is about as important as your social security number. Well, at least as far as your PC’s operating system goes. This is a random combination of numbers, letters, and dashes that you’ll seldom need, but when you do, you’re going to need to know where to find it. For Windows 11 users, there are multiple ways to access this crucial code, but we highly recommend writing it down and storing it in a safe place, too.

Read more
How to factory reset Windows 10 or Windows 11
Windows 10 Home vs. Pro

Returning Windows 10 or 11 to their defaults with a factory reset can be a great way to improve performance, clear our old unnecessary software, and make your PC feel like-new again. While you can always use our Windows speed up tricks to give your system a boost, sometimes there's no substitute for starting from scratch.

Here's how to factory reset Windows 10 and Windows 11 to get your PC feeling right again.

Read more
Best refurbished laptop deals: How to find cheap used computers
microsoft surface laptop go 2020 on desk

If you're shopping for laptops on a budget, then you probably don't want to aim for the best laptops on the market, since they often cost thousands of dollars and usually give you diminishing returns the more expensive they get. On the other hand, refurbished laptops are a great way to save money while also helping the environment and reducing e-waste. Not only that, but most refurbished laptops tend to be refurbished by the brand and are backed by warranties and return windows, so even if something is not right with your refurbished laptop, you can get a replacement or your money back.

To that end, there are really great refurbished laptop sales that you can check out as part of Best Buy laptop deals, Dell laptop deals, HP laptop deals and Lenovo laptop deals. Alternatively, if you're in the Apple ecosystem, take a look at these refurbished MacBook deals, or if you still want to go for something new, you could consider checking out these laptop deals instead.
Best Buy refurbished laptops -- starting at $113
Best Buy's refurbished laptops are -- you guessed it -- Geek Squad Certified and while they may not be free and clear of absolutely all cosmetic scuffs they are still exceptionally clean and always in working order. Some of them even come with additional software like virus tools, streaming access, like Apple TV+, and much more. Of course, the best part is that you can get a premium and fully upgraded model for less, often with more storage, more power, and more features than you would when buying a base model brand new. You've got some great options from Lenovo, Acer, HP, Dell, Gateway, and even Apple to choose from. The cheapest models start around $120 and increase from there. The best way to know what's available is to head over and browse for yourself.

Read more