Sub topic 6
Checking for blank cells
This chapter shows how to make an IF formula behave sensibly when a cell has nothing in it. You will compare the main ways to test for a blank. You will also see why some cells that look empty are not, and how to stop half-finished rows from producing misleading results.
It assumes you can write a basic =IF(test, value_if_true, value_if_false) formula. It also assumes you know the comparison operators (=, <>, >= and so on) and how to return text, numbers, or an empty string "". You should be able to copy a formula down a column.
Why blanks need their own test
Spreadsheets are often filled in over time. A grading sheet might have 200 rows ready, with scores entered for only 40 of them. If the formula ignores this, the empty rows get a result anyway:
=IF(B2>=50, "Pass", "Fail")When B2 is empty, Sheets treats it as 0 in a numeric comparison. 0>=50 is FALSE, so every unscored student shows "Fail". That is a wrong answer, not a missing one, and it is easy to overlook in a long column.
The fix is to test whether the cell is blank first. Only if it has something in it do you run the real test.
=IF(B2="", "", IF(B2>=50, "Pass", "Fail"))The outer IF asks "is B2 empty?". If so, it returns an empty string and the result cell looks blank. Otherwise the inner IF does the grading.
Three ways to test for a blank
Sheets gives you several tests that look similar but are not identical. The three you will use most are these.
Compare to an empty string
=IF(A2="", "Missing", "Entered")Two double quotes with nothing between them make an empty string, which is text with zero characters. The test A2="" is TRUE when A2 is truly empty. It is also TRUE when A2 holds a formula that returned "".
The opposite test uses <>:
=IF(A2<>"", "Entered", "Missing")Use whichever reads more naturally. Putting the "has data" case first often makes longer formulas easier to follow.
ISBLANK
=IF(ISBLANK(A2), "Missing", "Entered")ISBLANK returns TRUE only when the cell is completely empty. A cell containing a formula is never blank to ISBLANK, even if that formula displays nothing.
To reverse the test, wrap it in NOT:
=IF(NOT(ISBLANK(A2)), "Entered", "Missing")LEN equal to zero
=IF(LEN(A2)=0, "Missing", "Entered")LEN counts characters. A truly empty cell has length 0, and so does a formula result of "". This test is useful when you also want to apply other text logic to the same cell.
What each test does with tricky cells
The tests agree on a truly empty cell and disagree on the other cases. This table shows what each returns for four kinds of cell content.
| What is in A2 | `A2=""` | `ISBLANK(A2)` | `LEN(A2)=0` | `TRIM(A2)=""` |
|---|---|---|---|---|
| Nothing at all | TRUE | TRUE | TRUE | TRUE |
| A formula returning `""` | TRUE | FALSE | TRUE | TRUE |
| A single space | FALSE | FALSE | FALSE | TRUE |
| The number 0 | FALSE | FALSE | FALSE | FALSE |
Two points follow from the table.
- Formula cells. If the cell you are testing is itself the output of another formula that can return
"", useA2=""orLEN.ISBLANKwould report that the cell is not blank, even though it looks blank on screen. - Zero is not blank. A cell containing 0 is a real value.
A2=""correctly returns FALSE for it. This matters for scores and quantities, where 0 is a legitimate entry and you do not want it treated as missing.
The last column introduces a fourth test, which the next section covers.
Cells that look empty but are not
Data pasted from a website, an export, or a form often contains stray spaces. A cell with a single space looks blank, but A2="" is FALSE, so your formula treats it as data.
TRIM removes leading, trailing, and repeated spaces. Testing the trimmed value catches these cells:
=IF(TRIM(A2)="", "Missing", "Entered")Some pasted text contains a non-breaking space, which is character code 160 and which TRIM does not remove. If TRIM does not fix a cell that still seems blank, substitute that character out first:
=IF(TRIM(SUBSTITUTE(A2, CHAR(160), ""))="", "Missing", "Entered")You can check whether a cell holds hidden characters by putting =LEN(A2) in a spare cell. A "blank" cell that reports a length above 0 contains something invisible.
Blank versus zero in numeric tests
Comparing an empty cell to a number can surprise you. In Sheets an empty cell equals 0 in a numeric comparison, so this is TRUE for a truly empty B2:
=IF(B2=0, "Zero", "Not zero")An empty cell and a cell holding 0 therefore both return "Zero". If you need to tell them apart, test for blank first:
=IF(B2="", "Not entered", IF(B2=0, "Zero", "Has a value"))Order matters here. The blank test must come before the numeric test. If you reverse them, empty cells are caught by the B2=0 branch and the blank branch is never reached.
Returning an empty string and what it does downstream
Returning "" is the usual way to make a formula cell look empty. The cell is not actually empty, though. It holds text of length zero. This has consequences for formulas that read it.
- Arithmetic on it fails. If D2 contains
=IF(B2="", "", B2*2)and B2 is empty, then=D2+1returns a#VALUE!error, because you cannot add a number to text. SUM,AVERAGE, andMAXskip text, so they work correctly on a range that includes""results.COUNTignores the""cells, butCOUNTAcounts them, because they contain something.
If another formula must do arithmetic on the result, either guard that formula with its own blank test, or return a number that signals "no data" instead.
=IF(D2="", "", D2+1)Checking several cells at once
Often a row is only worth processing when every required field is filled in. Combine blank tests with AND and OR, which you met earlier.
Return a result only if both inputs are present:
=IF(OR(B2="", C2=""), "", B2*C2)This reads: if either B2 or C2 is empty, show nothing; otherwise multiply them. Using OR here is correct because one missing value is enough to make the calculation meaningless.
The mirror-image version says "both must be present":
=IF(AND(B2<>"", C2<>""), B2*C2, "")The two formulas give the same result. The difference between OR with ="" and AND with <>"" is a form of De Morgan's law. Choose the one you find easier to read.
For a whole row, COUNTA is shorter. It counts non-empty cells in a range:
=IF(COUNTA(A2:C2)=0, "Empty row", "Has data")You can also use it to flag incomplete rows:
=IF(COUNTA(A2:C2)<3, "Incomplete", "Complete")COUNTA counts a cell containing a formula that returns "", and it counts a cell holding only a space. If your range includes formula cells that can return "", COUNTA will over-count. In that case use COUNTIF(A2:C2, "<>") or test each cell individually.
Choosing a test
The flowchart below summarises how to choose a test for a given situation.
If you have no particular reason to choose otherwise, A2="" is a good default. It handles both typed-in blanks and formula blanks, and it needs no extra function.
Filling the formula down a column
Blank tests combine well with the fill-down habits from earlier. In a gradebook, a single formula can cover rows that are not yet filled in:
=IF(A2="", "", IF(B2="", "Awaiting score", IF(B2>=$F$1, "Pass", "Fail")))This formula has three layers.
- If there is no student name in A2, the row is unused and the result is empty.
- If there is a name but no score, the result is "Awaiting score".
- If both are present, the score is compared with the pass mark in F1. The
$F$1reference stays fixed as you copy the formula down.
Because the formula is written for the whole column, new rows work as soon as you type into them. You do not need to edit the formula again.
Common mistakes
- Using
=" "with a space inside the quotes.A2=" "tests for a single space, not for emptiness. Use""with nothing between the quotes. - Using
ISBLANKon a formula cell. It returns FALSE for a formula that displays nothing, so rows you expected to skip are processed. Switch toA2="". - Testing the number first.
IF(B2>=50, ..., ...)runs before any blank check, so empty cells are treated as 0. Put the blank test on the outside. - Forgetting that 0 is a value.
IF(B2, "Entered", "Missing")treats 0 as FALSE and reports "Missing". UseB2<>""instead. - Adding to a cell that may be
"". Guard the arithmetic, or the#VALUE!error spreads down the sheet.
Summary
- Compare to
""as the default blank test. It works for typed-in blanks and for formulas that return"". - Use
ISBLANKonly when you must distinguish a truly empty cell from one holding empty text. - Use
TRIMwhen the data may contain stray spaces, andSUBSTITUTEwithCHAR(160)for non-breaking spaces. - Put the blank check outside the real test, so empty rows never reach a numeric comparison that treats them as 0.
- Use OR or AND to check several inputs, and
COUNTAfor whole rows, remembering its limits on formula cells.
Exercise
Column A holds student names, column B holds scores, and F1 holds the pass mark. Some rows have a name but no score yet, and some rows are completely unused. Write one formula for C2 that returns an empty string for unused rows, "Awaiting score" when only the score is missing, and "Pass" or "Fail" otherwise. Then explain why ISBLANK(B2) could give a wrong answer here if B2 were itself a formula.
Show answer
Use =IF(A2="", "", IF(B2="", "Awaiting score", IF(B2>=$F$1, "Pass", "Fail"))). The name test comes first so unused rows return nothing, the score blank test comes second so an empty B2 is not read as 0, and the final IF compares against the fixed pass mark $F$1. If B2 held a formula that returned "", ISBLANK(B2) would be FALSE because the cell contains a formula, so the row would fall through to the numeric comparison and be marked "Fail". B2="" returns TRUE in that case.
Exercise
A cell A5 looks empty, but =IF(A5="", "Missing", "Entered") returns "Entered". Describe two steps you would take to find out why, and one formula that would treat the cell as missing.
Show answer
First, enter =LEN(A5) in a spare cell. A result above 0 means the cell contains something invisible, such as a space. Second, enter =ISBLANK(A5) to confirm it is not truly empty. If the cell holds ordinary spaces, =IF(TRIM(A5)="", "Missing", "Entered") treats it as missing. If LEN is still above 0 after TRIM, the cell probably contains a non-breaking space, so use =IF(TRIM(SUBSTITUTE(A5, CHAR(160), ""))="", "Missing", "Entered").