The Excel IF function returns one value when a condition is true and another when it is false. The basic shape is =IF(logical_test, value_if_true, value_if_false), so a formula like =IF(A1>50,"Pass","Fail") shows Pass when the value in A1 is above 50 and Fail when it is not. You can type it straight into a cell or build it with the Insert Function dialog, and once it works you can copy it down a column, nest it, or combine it with AND, OR and COUNTIF to handle more complex decisions.

What You'll Need

  • Excel on Windows, Mac, or Excel for the web (the function works identically in all three; menu names can differ slightly by version, device and region)
  • Your data already in cells, ideally with a header row so formulas are easier to read
  • Basic familiarity with cell references such as A1 and ranges such as B2:B50
  • Awareness of whether your region uses commas or semicolons between arguments - Excel accepts commas normally, but some locales display semicolons

Step-by-Step

  1. Pick the cell for your result. Click an empty cell beside the first row of data, for example C2 if your values sit in A2 and B2. This is where the answer will appear.
  2. Start the formula with an equals sign. Type =IF(. Excel immediately shows a tooltip listing the three arguments, which is a quick reminder of the order.
  3. Write the test. Enter a comparison such as A2>50. Use these operators: > greater than, < less than, >= greater or equal, <= less or equal, = equal to, <> not equal to. Text comparisons need quotes: A2="Yes".
  4. Add a comma and the true result. Type , then the value to show when the test passes. Text must be in double quotes ("Pass"); numbers go in bare (1). You can also point to another cell or run a small calculation.
  5. Add a comma and the false result. Type the value for when the test fails, for example "Fail", then close with ). The finished formula reads =IF(A2>50,"Pass","Fail").
  6. Press Enter and check the result. The cell shows the correct branch for the first row. Click the cell and look at the formula bar to confirm Excel stored what you intended.
  7. Copy the formula down. Drag the fill handle (the small square at the bottom-right corner of the selection) down the column, or copy the cell and paste it into the rows below. Relative references adjust automatically, so A2 becomes A3, A4 and so on.
  8. Handle blanks and errors. Wrap the test in a check such as =IF(A2="","",IF(A2>50,"Pass","Fail")) to leave empty rows blank instead of showing Fail. If a lookup inside the formula can fail, use IFERROR around the whole thing.
  9. Nest a second condition if needed. For a grade band, write =IF(A2>=90,"A",IF(A2>=80,"B",IF(A2>=70,"C","Below C"))). Excel allows up to 64 nested IFs, but past three or four levels consider the IFS function or a lookup table for readability.
  10. Test with AND or OR. To require two conditions, use =IF(AND(A2>=50,B2="Yes"),"Approve","Review"). For either condition, swap AND for OR. Each test inside AND/OR is separated by a comma.
  11. Count or sum conditionally instead. If you only need totals, use COUNTIF(range, criteria) or SUMIF(range, criteria, sum_range) rather than IF, which is faster and easier to read.
  12. Save and verify a few rows by hand. Pick two or three rows, work out the expected answer yourself, and compare. This catches reversed operators and off-by-one thresholds before the sheet is shared.

Common Mistakes

  • Forgetting quotes around text. =IF(A2>50,Pass,Fail) fails because Excel looks for named ranges called Pass and Fail. Use "Pass" and "Fail".
  • Using the wrong number of arguments. IF needs two or three. A missing comma or an extra one produces "too many arguments" or "you've entered too few arguments".
  • Comparing numbers stored as text. Values imported from other systems sometimes sit left-aligned as text. A2>50 then behaves unexpectedly. Convert them with the Text to Columns tool or multiply by 1 in a helper column.
  • Mixing up true and false. Swapping the second and third arguments silently gives the opposite answer, which is easy to miss on a quick glance.
  • Nesting beyond the closing brackets. Every IF you open needs its own closing parenthesis. Use Excel's coloured bracket hints or press Ctrl+Shift+Enter history to spot the gap.
  • Hard-coding thresholds everywhere. Typing 50 into dozens of formulas makes later changes painful. Put the limit in one cell and reference it, for example $B$1.

Tips

  • Name your thresholds in a small table and reference them with absolute references (dollar signs) so copying the formula does not shift them.
  • Return blanks with "" rather than spaces so charts and pivot tables do not count empty-looking cells.
  • Use IFS when you have several bands: =IFS(A2>=90,"A",A2>=80,"B",A2>=70,"C",TRUE,"Below C"). Order matters - the first true test wins.
  • Select part of a formula in the formula bar and press F9 to see what it evaluates to, then undo with Ctrl+Z. This is a quick way to locate a broken piece.
  • Apply data validation or conditional formatting based on the same logic to make results visually obvious without extra columns.
  • Keep one formula per row and copy rather than retype; hand-editing rows is where inconsistency creeps in.

Troubleshooting

If the formula shows #NAME?, Excel is reading your text as a name: add quotes around any literal text. #VALUE! usually points to a number stored as text or an empty cell used in arithmetic - check the source column's formatting. A blank result when you expected text can mean the false branch is missing, so add the third argument.

If the cells show the formula text instead of the answer, the cell is formatted as Text. Change the format to General, then re-enter the formula (pressing F2 and Enter on each cell is the fastest fix). If a copied formula returns the same answer for every row, check whether you used dollar signs too early or missed the fill handle; click a lower cell and inspect the references in the formula bar. If the logic collapses at the boundary, test with >= rather than > and confirm the threshold value itself behaves as intended.

If a large sheet suddenly calculates slowly, look for whole-column references like A:A inside IF. Narrow them to the used range. If results look stale, press F9 to recalculate, or check that calculation is set to automatic in the Formulas section of Excel options.

If that did not work: rebuild the formula in a blank cell one argument at a time to isolate the failing part, and compare against a known-good row. When a nested formula becomes unmanageable, split it into helper columns - one for each test - and combine the helper results in a final IF. That is easier to audit and faster to fix later than one giant formula.

Frequently Asked Questions

Can IF return a blank cell?

Yes. Use an empty string as the result, like =IF(A2>50,"Pass",""). The cell looks empty but still contains a formula.

How many conditions can I nest?

Excel allows up to 64 nested IF functions. For more than a few levels, IFS or a lookup table is far easier to maintain.

What is the difference between AND and OR in IF?

AND requires every test to be true for the true branch to run. OR runs the true branch if any one test is true.

Why does my IF formula return a#VALUE! error?

Most often a cell contains text where a number is expected, or the result branch contains an invalid calculation. Reformat the source cells and rebuild the arithmetic part.

Does IF work the same on Excel for the web and mobile?

The function behaves the same, but the mobile apps have limited formula-editing tools. Building the formula on desktop and opening it on mobile is usually easier.

Can I use wildcards in an IF test?

Not directly with the equals operator. Combine IF with COUNTIF or use SEARCH inside ISNUMBER for partial-text matching.