The Excel IF function is how you write an "if else" statement in a spreadsheet: =IF(logical_test, value_if_true, value_if_false). You give Excel a condition to check, tell it what to show when the condition is true, and what to show when it is false. For example, =IF(A1>=60,"Pass","Fail") displays Pass when the score in A1 is 60 or above and Fail otherwise. That single formula covers most if/else needs; nesting or combining it with AND and OR handles the rest.
One thing to know before you start: Excel has no separate "else if" keyword. You chain extra tests by placing another IF inside the value_if_false position. Everything below works the same in Excel for Microsoft 365, Excel 2021 and 2019, and in Excel for the web; older versions lack the newer IFS and LET functions noted where relevant.
What You'll Need
- A spreadsheet with data in cells you can reference, such as a number, a date or text.
- A clear idea of your test and the two possible results, written out in plain language first. "If sales are over 500, show Bonus, otherwise show None" prevents most formula mistakes.
- Text results wrapped in double quotation marks; numbers left bare.
- Familiarity with how your Excel separates arguments. Most versions use commas; some regional settings use semicolons. Labels and separators can differ slightly by version and region, so match what your own formulas show.
Step-by-Step
- Pick the result cell. Click the cell where the answer should appear, usually beside the row you are testing. Type an equals sign to start the formula.
- Type IF and open the bracket. Enter
=IF(. Excel shows argument hints below the formula bar as you go, which is a quick way to check you are in the right place. - Write the logical test. This is a comparison that gives TRUE or FALSE. Use
=,>,<,>=,<=or<>(not equal to). For text comparisons, put the text in quotes, for exampleB2="Yes". Test cell:=IF(A1>=60, - Enter the value if true. Add what should appear when the test passes, followed by a comma. Text goes in quotes; a number, a cell reference or another formula does not. Example:
=IF(A1>=60,"Pass", - Enter the value if false and close the bracket. Finish with the alternative result and a closing bracket. The complete formula is
=IF(A1>=60,"Pass","Fail"). Press Enter to run it. - Copy the formula down. Drag the small square at the bottom-right corner of the cell, or copy the cell and paste it into the rows below. Relative references adjust automatically, so A1 becomes A2, A3 and so on.
- Add an else-if by nesting. Put a second IF in the false position. A grading example:
=IF(A1>=90,"A",IF(A1>=80,"B",IF(A1>=70,"C","F"))). Each nested IF has its own brackets; count them if Excel refuses the formula. Order matters: test the highest threshold first, because Excel stops at the first TRUE result. - Combine conditions with AND or OR. Wrap multiple tests inside the logical_test position. AND requires every condition to be true:
=IF(AND(A1>=60,B1="Paid"),"Ship","Hold"). OR needs just one:=IF(OR(C1="Urgent",D1>7),"Escalate","Normal"). You can mix them, and you can nest AND inside OR. - Use IFERROR to hide ugly errors. Wrap the whole formula when a lookup or division might fail:
=IFERROR(A1/B1,"n/a")shows n/a instead of #DIV/0!. - Leave a result blank when needed. To show nothing instead of a word, use two double quotes with nothing between them as the result:
=IF(A1="","",A1*2). - Check with test values. Temporarily change a cell to trigger the other branch and confirm both results appear as expected. Undo the change with Ctrl+Z (Cmd+Z on Mac) when done.
If you are on a modern Excel version with dynamic arrays and want to avoid deep nesting, the IFS function takes pairs of test and result: =IFS(A1>=90,"A",A1>=80,"B",A1>=70,"C",TRUE,"F"). The final TRUE pair acts as your else. IFS is not available in Excel 2016 or earlier, where nested IF remains the way to go.
Common Mistakes
- Unquoted text.
=IF(A1=Yes,"x","y")fails because Excel reads Yes as a name. Write"Yes"instead. - Mismatched brackets. Every IF needs its own closing bracket. Excel usually offers to fix it, but the suggestion can be wrong, so count them manually on long formulas.
- Wrong test order in nested IFs. Testing
A1>=70beforeA1>=90means a score of 95 returns C, because Excel takes the first true branch and stops. - Using if/else when a lookup is better. Long chains of nested IFs are hard to read and edit. For grade bands, tax brackets or commission tiers, a lookup table with VLOOKUP or XLOOKUP is easier to maintain.
- Comparing text to numbers. Numbers stored as text (often left-aligned) never satisfy a numeric test. Convert them with the Text to Columns tool or Value option in Paste Special.
- Forgetting commas between arguments. Each of the three parts must be separated; a missing comma produces a formula error dialog rather than a result.
- Extra spaces in text.
"Yes "is not the same as"Yes". Use TRIM on the source cell or clean the data.
Tips
- Build the formula from the inside out in a spare cell first, then paste it into the full formula. It is much easier to debug one nested IF before adding three more.
- Name your thresholds in separate cells and reference them instead of typing numbers:
=IF(A1>=$F$2,"Pass","Fail")lets you change the pass mark once for the whole sheet. - Press F9 on a highlighted section of a formula to see what it evaluates to, then Escape to restore it. This reveals which branch Excel is taking.
- Use the Formulas tab and choose Evaluate Formula to step through a nested IF cell by cell.
- Color-code the cells your formulas depend on so the logic is obvious to anyone else reading the sheet.
- Keep nesting to a reasonable depth. Beyond three or four levels, readability drops sharply and the error risk climbs.
Troubleshooting
The formula shows #NAME? Text is missing quotes, or a function name is misspelled. Check every word result for double quotation marks.
You get #VALUE! One of your arguments is a type Excel cannot handle, often text where a number is expected, or a stray character. Select the cell and review each argument.
The result is always the false value. The test is comparing incompatible types or has a hidden space. Use TRIM and check whether the cell is text or numeric by looking at its alignment and the cell format list.
Excel asks if you meant to type a formula. This appears when a quote or bracket is unbalanced or you used the wrong separator. Cancel the suggestion if it looks wrong and inspect the formula bar.
Copying gives wrong answers. You are probably using absolute references where relative ones are needed, or vice versa. Press F4 on a reference to cycle through the $ combinations.
The formula is too long to follow. Break it into helper columns, one decision per column, then combine the results in a final formula. Alternatively, upgrade to IFS where your version supports it.
Frequently Asked Questions
Does Excel have an ELSEIF function?
No. You emulate else-if by nesting an IF inside the value_if_false position, or by using IFS in newer versions.
Can I use IF to check for blank cells?
Yes. =IF(A1="","Blank","Filled") works for cells that are genuinely empty. For a cell holding a formula that returns empty text, use ISBLANK only if you understand it returns FALSE for that case.
How many IF statements can I nest?
Excel allows 64 levels of nesting, but anything beyond a few is hard to maintain. Use IFS or a lookup table for long chains.
Can IF return a color or formatting?
Not directly. IF returns a value; formatting changes come from Conditional Formatting rules, which can use a formula as their test.
Why does my IF formula return 0 when the cell looks empty?
The false value is returning a reference to an empty cell, which Excel displays as 0. Replace the reference with "" to show blank.
Is there a limit on text length in results?
The returned string follows Excel's cell text limit, which is 32,767 characters. Results longer than the cell width display truncated but remain intact in the formula bar.