How to Write an IF Statement in Excel
In this article
In Excel, an IF statement is written as =IF(condition, value_if_true, value_if_false). Type it into a cell, press Enter, and Excel checks the condition and returns one of the two values.
Time 2 min · Steps 6 · Level Easy
Which IF Form Do You Need?
Start by deciding what you are comparing, because that picks the formula shape. A simple yes/no comparison needs the basic IF. A grade or tier with more than two outcomes needs nested IFs or the newer IFS function. A check for blank cells needs ISBLANK or a test like A1="". Text comparisons need quotation marks around the text; numbers do not.
One rule that trips people up: text values in the result, such as "Pass" or "Low", must be wrapped in double quotes. Numbers, cell references and other formulas need no quotes. Excel separates the three parts with commas in most regional settings, but some regions use semicolons — if Excel shows an error right after typing a comma, try a semicolon instead.
How to Write a Basic IF Statement
- Click the cell where you want the result, for example cell C2 next to your first row of data.
- Type the opening =IF( — the equals sign tells Excel this is a formula.
- Enter the condition, such as B2>=50, which checks whether the value in B2 is 50 or more.
- Add the true result after a comma, in quotes if it is text: =IF(B2>=50,"Pass",
- Add the false result and close the bracket: =IF(B2>=50,"Pass","Fail")
- Press Enter, then drag the small square at the bottom-right corner of the cell down to copy the formula to the rows below.
Once the formula is in place, Excel recalculates it automatically. Change B2 to 45 and C2 flips from "Pass" to "Fail" with no extra work.
Worked Example: Grading Test Scores
Suppose column A holds 30 student names and column B holds scores out of 100. You want column C to show "Pass" for 50 and above, "Fail" below 50, and column D to sort results into three tiers. In C2, type =IF(B2>=50,"Pass","Fail") and copy it down to row 31 — that is 30 formulas filled in a couple of seconds by dragging.
For the three-tier version in D2, nest one IF inside another: =IF(B2>=75,"High",IF(B2>=50,"Medium","Low")). Excel checks 75 first; anything below 75 falls to the second IF, which checks 50. Order matters — if you test 50 first, everything 50 and above gets "Medium" and "High" never appears. Copy that down the same way.
Check the result the quick way: click any result cell and confirm the formula bar shows the formula with the right row number. If D30 still says B2 instead of B30, the fill did not copy — select D2, copy it, select D3:D31, and paste.
What Goes Wrong and How to Fix It
Most IF problems come from four places, and each has a quick fix. If Excel shows #NAME?, you likely missed a quote around text or misspelled IF. If it shows #VALUE!, the condition may be comparing text to a number, for example B2>50 where B2 contains "50" typed as text; retype the cell value as a number. If the formula shows as plain text instead of calculating, the cell is probably formatted as Text — right-click, choose Format Cells, set it to General, then re-enter the formula.
If the result is always the false value even though the condition looks right, check for hidden spaces. "Pass " with a trailing space does not equal "Pass". The TRIM function removes them: =IF(TRIM(A2)="Pass",1,0). And if a blank cell returns 0 or "Fail" when you expected blank, add a front check: =IF(B2="","",IF(B2>=50,"Pass","Fail")) — the empty quotes make the cell stay empty until a score is entered.
When Should You Use IFS Instead of Nested IFs?
Use IFS when you have three or more outcomes, because it reads more cleanly than stacked IFs. The grading example becomes =IFS(B2>=75,"High",B2>=50,"Medium",TRUE,"Low") — each condition and result is a pair, and TRUE acts as the catch-all for everything else. IFS is available in current Excel versions; if typing it gives #NAME?, your version does not include it and nested IFs are the fallback. Labels and function availability can differ slightly by Excel version and region.
Two related functions worth knowing once IF makes sense: AND and OR let one IF test several conditions at once, so =IF(AND(B2>=50,C2>=50),"Pass","Fail") requires both scores, while OR requires just one. COUNTIF then tallies the results, so =COUNTIF(C2:C31,"Pass") tells you how many of the 30 students passed.
Official source: Microsoft Support