Sub topic 12
Common mistakes and how to fix them
This chapter assumes you can enter formulas, use cell references such as B2, copy a formula down a column with the fill handle, and write basic IF formulas with AND, OR, nested IF, and IFS. It collects the errors that show up most often and gives a way to diagnose each one.
A working model for troubleshooting
An IF formula fails in one of three ways:
- Excel rejects it. You see a message box, or the cell shows an error such as
#NAME?or#VALUE!. - Excel accepts it but returns the wrong result. This is the most dangerous case because nothing looks broken.
- It works in one row and fails after copying. This is nearly always a reference problem.
Work in this order: check the syntax, then the logical test, then the returned values, then the references. Most problems are found in the first two steps.
Syntax mistakes
Missing quotes around text
Text in a formula must be inside double quotes. Without quotes, Excel treats the word as a name and returns #NAME?.
=IF(B2>=60,Pass,Fail)The fix is to quote both results:
=IF(B2>=60,"Pass","Fail")The same rule applies to text on the right side of a comparison. A2="Yes" compares with the text Yes. A2=Yes asks Excel to look for a name called Yes.
The reverse mistake also happens. Numbers in quotes become text. "60" is not the number 60, so a formula that returns "60" gives a value that will not add up in later calculations.
Unbalanced parentheses and misplaced commas
Every opening parenthesis needs a closing one. This matters most in nested formulas, where the closing parentheses pile up at the end. A nested IF with three IF calls needs three closing parentheses.
=IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F")))Excel colors matching pairs as you type. If the formula is long, click into it and watch which parentheses highlight.
Be careful with the argument separator too. Many regional settings use a semicolon instead of a comma. If you copy a formula from a web page and get a rejection message, the separator is a likely cause. Use whichever separator your Excel shows in its own function tooltips.
Too many or too few arguments
IF takes up to three arguments: the test, the value if true, and the value if false. Two behaviors catch people out:
- If you leave out the false argument and end with a comma, as in
=IF(B2>=60,"Pass",), the result is0when the test is false. - If you leave out the comma as well, as in
=IF(B2>=60,"Pass"), the result is the wordFALSEwhen the test is false.
Both are legal, which is why they are easy to miss. If you want an empty cell appearance, return an empty string explicitly:
=IF(B2>=60,"Pass","")Logical test mistakes
Using the wrong operator
The six comparison operators are =, <>, >, <, >=, and <=. Common slips:
| Mistake | Problem | Correct form |
|---|---|---|
| `B2=>60` | Operator order is reversed and Excel rejects it | `B2>=60` |
| `B2=<60` | Same problem | `B2<=60` |
| `B2!=60` | `!=` comes from other languages and is not valid | `B2<>60` |
| `B2==60` | `==` is not valid | `B2=60` |
The second kind of operator error is a boundary error. Suppose the rule is "60 or higher passes". Writing B2>60 is valid, but a score of exactly 60 fails. Whenever you write a test, check the boundary value on purpose. Type 60 into a test cell and see what comes back.
Comparing text as if it were a number
A cell that looks like a number may be stored as text. This often happens after importing data or pasting from a web page. The cell is usually left-aligned, and a small green triangle may appear in the corner.
A text value "75" compared with a number behaves in a surprising way. In Excel's comparison rules, text is always considered greater than any number. So ="75">=60 is TRUE, but so is ="5">=60. A test that should fail passes.
To check what a cell holds, use ISNUMBER in a spare cell:
=ISNUMBER(B2)If it returns FALSE for a value that looks numeric, convert the data. Options include Data > Text to Columns on the whole column, multiplying by 1 in a helper column, or using VALUE:
=IF(VALUE(B2)>=60,"Pass","Fail")VALUE returns #VALUE! when the text cannot be read as a number, which at least makes the problem visible.
Hidden spaces in text
A cell that looks like Yes may actually contain Yes with a trailing space. The test A2="Yes" then returns FALSE. Use TRIM to remove extra spaces:
=IF(TRIM(A2)="Yes","Approved","Pending")Remember that the comparison ignores upper and lower case, so yes, YES, and Yes all match. If you need a case-sensitive test, use EXACT:
=IF(EXACT(A2,"Yes"),"Approved","Pending")Comparing with the wrong kind of blank
An empty cell and a cell holding an empty string are different things, although A2="" is true for both. A cell that holds a formula returning "" looks blank but is not empty. ISBLANK(A2) returns FALSE for it. When you test for blanks, A2="" is usually the safer choice because it covers both cases. Use ISBLANK only when you want to exclude formula cells that return an empty string.
Also remember that an empty cell counts as 0 in a numeric comparison. In =IF(B2<60,"Fail","Pass"), a blank B2 returns Fail, because blank is treated as 0. If blank rows should stay empty, test for the blank first:
=IF(B2="","",IF(B2>=60,"Pass","Fail"))Mistakes with AND, OR, and NOT
Writing the condition the way you say it
People often write conditions as they would in a sentence. These forms do not work as intended:
=IF(B2>=60 AND C2>=60,"Pass","Fail")
=IF(B2>=60 AND <=100,"Valid","Check")
=IF(D2="Gold" OR "Platinum","Priority","Standard")The first uses AND as an operator, which Excel does not accept. The second leaves out the cell on the right side of the second comparison. The third is accepted by some people's intuition but not by Excel's logic: "Platinum" on its own is not a comparison. In Excel, AND and OR are functions, and each condition must be a full test:
=IF(AND(B2>=60,C2>=60),"Pass","Fail")
=IF(AND(B2>=60,B2<=100),"Valid","Check")
=IF(OR(D2="Gold",D2="Platinum"),"Priority","Standard")Confusing AND with OR
A wrong choice here gives a formula that runs without error and gives wrong results. A reliable check is to read the formula aloud with the word "both" or "either":
- AND means both conditions must be true.
- OR means at least one must be true.
A common trap involves "not equal" tests. Suppose you want to flag any status that is neither "Closed" nor "Cancelled". This version looks right but flags every row:
=IF(OR(E2<>"Closed",E2<>"Cancelled"),"Open","Done")Any value is different from at least one of the two words, so the OR is always true. Use AND with <> tests, or wrap an OR in NOT:
=IF(AND(E2<>"Closed",E2<>"Cancelled"),"Open","Done")
=IF(NOT(OR(E2="Closed",E2="Cancelled")),"Open","Done")Chained comparisons
Mathematical notation such as 60<=B2<=100 does not work as a range test in Excel. Excel evaluates 60<=B2 first, gets TRUE or FALSE, and then compares that result with 100. Because a logical value is considered greater than any number, the result is not what you meant. Use AND(B2>=60,B2<=100).
Nested IF mistakes
Tests in the wrong order
In a nested IF, the first true test wins and the rest are never evaluated. This formula grades every score of 70 or higher as C:
=IF(B2>=70,"C",IF(B2>=80,"B",IF(B2>=90,"A","F")))A score of 95 passes the first test and returns C. Order the tests from the strictest threshold to the loosest, as in the earlier correct version. If you test from low to high, use < operators and reverse the logic consistently. Do not mix directions in one formula.
Missing the final default
Every branch except the last contains another IF. The last false argument is the default result for everything that failed all the tests. If you omit it, such rows return FALSE, which looks like a bug in the data. Always decide what the default means and write it.
Formulas too deep to maintain
Excel allows up to 64 nested levels, but readability breaks down far earlier. Past three or four levels, consider these alternatives:
- Use IFS for flat lists of tests, available in Excel 2019 and Microsoft 365.
- Put thresholds in a lookup table and use a lookup function. That topic is outside this chapter, but it is the right tool when the list of grades or bands will change.
IFS mistakes
IFS has no built-in default. If no test is true, it returns #N/A. That is why the grade example ends with TRUE,"F":
=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")Leaving off the final TRUE pair is the most common IFS error. Also, IFS needs pairs: an odd number of arguments causes an error message. Finally, IFS does not exist in Excel 2016 and earlier. A workbook shared with someone on an older version shows #NAME? in those cells.
Reference mistakes when copying down
Missing dollar signs on the threshold cell
Suppose the target is in F1, and you write:
=IF(B2>=F1,"Target met","Below target")Row 2 works. When you fill down, the reference moves to F2, then F3, and so on, and those cells are empty. Every row after the first now compares against 0. The fix is an absolute reference:
=IF(B2>=$F$1,"Target met","Below target")Click inside the reference and press F4 to cycle through F1, $F$1, F$1, and $F1. For a single threshold used by a whole column, $F$1 is correct.
Over-locking references
The opposite mistake is putting dollar signs on the reference that should move. $B$2 copied down always reads B2, so every row returns the same answer as row 2. Lock only the threshold, not the value being tested.
Hard-coded numbers in many formulas
Typing 60 into every formula works until the pass mark changes. Then you must edit every formula and may miss one. Store the value in a cell and refer to it, as shown above.
Guarding errors without hiding problems
IF can prevent errors such as division by zero:
=IF(C2=0,"",B2/C2)Use this kind of guard for expected situations only. If you wrap every formula so that it returns "" on any problem, real data faults become invisible. Prefer a specific test, like C2=0, over a general error catch. Also note that a result of "" is text. A later formula such as =D2+1 on that cell returns #VALUE!. If downstream formulas need numbers, return 0 or handle the blank in those formulas.
A repeatable checklist
Run through these steps whenever an IF formula gives a puzzling result:
- Select the formula cell and use Formulas > Evaluate Formula to step through the calculation.
- Copy the logical test alone into a spare cell, without the IF, and see whether it returns
TRUEorFALSE. - Test boundary values: exactly on the threshold, one below, and one above.
- Test a blank cell and a text value where a number is expected.
- Fill the formula down and check the last row, not only the first.
Exercise
A sheet has pass marks of 60 in F1. The formula =IF(B2>=F1,"Pass","Fail") in C2 works, but after filling down, nearly every row below shows "Pass" even when scores are low. What is wrong, and what is the corrected formula?
Show answer
The threshold reference F1 is relative, so it moves to F2, F3, and so on when copied down. Those cells are empty and count as 0, so almost every score passes. Lock it with an absolute reference: =IF(B2>=$F$1,"Pass","Fail").
Exercise
You want to label orders that are neither "Closed" nor "Cancelled" as "Open". The formula =IF(OR(E2<>"Closed",E2<>"Cancelled"),"Open","Done") labels every order "Open". Explain why and give two corrected formulas.
Show answer
Every value differs from at least one of the two words, so the OR test is always true. Use AND: =IF(AND(E2<>"Closed",E2<>"Cancelled"),"Open","Done"). Or use NOT with OR: =IF(NOT(OR(E2="Closed",E2="Cancelled")),"Open","Done").
Exercise
The grade formula =IF(B2>=70,"C",IF(B2>=80,"B",IF(B2>=90,"A","F"))) returns "C" for a score of 95. Why, and how do you fix it?
Show answer
The first test, B2>=70, is true for 95, so the formula returns "C" and never reaches the other tests. Order the tests from highest to lowest: =IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F"))).