How to Use the IF Function in Excel
The IF function in Excel checks whether a condition is true or false, then returns one result if it is true and another result if it is false.
For example, this formula checks whether sales in B5 meet a target in C5:
=IF(B5>=C5,"Met","Not Met")
If sales are equal to or greater than the target, Excel returns Met. Otherwise, it returns Not Met.
IF function syntax
=IF(logical_test, value_if_true, value_if_false)
IF formula has a condition to test and the results to return for true and false outcomes.logical_testis the condition Excel checks, such asB5>=C5.value_if_trueis the result when the condition is true, such as"Met".value_if_falseis the result when the condition is false, such as"Not Met".
Example: mark a sales target as Met or Not Met
Suppose column B contains sales and column C contains each person’s target. In the first result cell, enter:
=IF(B5>=C5,"Met","Not Met")
Then copy the formula down. The references change for each row, so every salesperson is compared with their own target.
Comparison operators to use with IF
| Operator | Meaning | Example condition |
|---|---|---|
= | Equal to | A2=B2 |
> | Greater than | A2>100 |
< | Less than | A2<100 |
>= | Greater than or equal to | A2>=100 |
<= | Less than or equal to | A2<=100 |
<> | Not equal to | A2<>"Closed" |
Use IF with text
Text that you type directly into an IF formula needs double quotation marks. For example:
=IF(A2="Paid","Complete","Follow up")
This checks whether A2 contains the text Paid. If it does, Excel returns Complete; otherwise, it returns Follow up.
Do not put quotation marks around a cell reference. Use A2, not "A2". The first reads the value in the cell; the second is only the text A2.
Use IF to return a number or a calculation
IF can return more than text. This formula calculates how far sales are above target, but returns a blank when the target was not met:
=IF(B5>C5,B5-C5,"")
Notice that the blank result is written as "": two quotation marks with nothing between them. Excel treats this as an empty text result.
Common IF function mistakes
Forgetting quotation marks around text
Use "Met", not Met. Without quotation marks, Excel may return #NAME? because it assumes Met is a named range or function.
Using the wrong comparison operator
Use >= when a value equal to the target should count as meeting it. If you use only >, a value exactly equal to the target returns the false result.
Copying a formula with the wrong references
After filling an IF formula down, select a copied cell and inspect the formula bar. The row references should change consistently. For help with fixed rates or settings, read How to Lock a Cell in Excel with $ and F4.
Building a long nested IF too early
A simple IF is easy to read and maintain. If you need to test several independent conditions, use AND or OR; if you need to map many values to results, a lookup table may be easier to update than a long nested formula. For practical formulas that test multiple conditions, read How to Use IF with AND and OR in Excel.
Source and further reading
Microsoft explains the IF function syntax and examples, including text results and comparison logic. For the current comparison-operator reference, see Using calculation operators in Excel formulas.
Join the conversation