How to Use the IF Function in Excel
Return one value when a test is true and another when it is false with Excel's IF function, including AND, OR, nested IF, and IFS examples.
You want a cell to show one thing when a condition holds and something else when it does not. IF runs the test and returns the matching result.
Type the formula
=IF(B2>=50, "Pass", "Fail")
logical_testis the comparison to check, here whether B2 is 50 or more.value_if_trueis what to return when the test passes.value_if_falseis what to return when it fails.
If B2 holds 72, the cell shows Pass. If B2 holds 41, it shows Fail.
Fill the formula down
Select the cell and double-click the small square in its bottom-right corner. Excel copies the formula down as far as the neighboring column has data, adjusting B2 to B3, B4, and so on.
Combine conditions with AND or OR
Put AND or OR inside the test when more than one thing has to be checked:
=IF(AND(B2>=50, C2>=50), "Pass", "Fail")
AND needs every condition to be true. Swap in OR when any one of them is enough:
=IF(OR(B2>=50, C2>=50), "Pass", "Fail")
Nest IF for more than two outcomes
Put another IF in the false slot. Excel checks from left to right and stops at the first true test:
=IF(B2>=80, "A", IF(B2>=65, "B", IF(B2>=50, "C", "F")))
A score of 72 fails the first test, passes the second, and shows B.
Use IFS in Microsoft 365
IFS takes pairs of tests and results and is shorter to read than nested IF:
=IFS(B2>=80, "A", B2>=65, "B", B2>=50, "C", TRUE, "F")
The final TRUE pair is the catch-all. Without it, a value that matches nothing returns a #N/A error. IFS is available in Microsoft 365 and Excel 2019 or later.
If the result is text. Wrap it in double quotes, as in "Pass". Numbers and cell references go without quotes. To leave the cell blank on one branch, use a pair of empty quotes: =IF(B2="", "", B2*1.1).
If the test itself can produce an error. Wrap the whole thing in IFERROR: =IFERROR(IF(B2/C2>1, "Over", "Under"), "Check input"). A division by zero then shows the message instead of #DIV/0!.
More Excel how-tos
- How to Add a Drop-Down List in Excel
- How to Add a Line Break in an Excel Cell
- How to Convert Text to Numbers in Excel
- How to Create a Pivot Table in Excel
- How to Freeze Panes in Excel
- How to Lock Cells in Excel
- How to Make a Chart in Excel
- How to Merge Cells in Excel
- How to Remove Duplicates in Excel
- How to Split Text into Columns in Excel
- How to Sum a Column in Excel
- How to Use COUNTIF in Excel
- How to Use SUMIF in Excel
- How to Use VLOOKUP in Excel
- How to Use XLOOKUP in Excel