Sub topic 12
Handle no matches and blocked output ranges
This chapter assumes you can write the SORT and FILTER formulas from the previous chapters and combine them in one formula. You also need to know how a formula result "spills" into neighboring cells. Here you will learn what happens when FILTER finds nothing, what happens when the cells it needs are already occupied, and how to handle both so your sheet stays readable.
Why these two errors appear
SORT and FILTER are array formulas. You write the formula in one cell, and Sheets fills the cells to the right and below with the result. That area is called the spill range. Two situations break this:
- The result has zero rows.
FILTERhas nothing to return, so there is nothing to spill. - The result has rows, but something else already sits in the cells the result needs to fill.
Both produce an error in the formula cell. The two errors are different, and so are their fixes.
| Situation | Error shown | Typical cause |
|---|---|---|
| No row meets the condition | `#N/A` with "No matches are found in FILTER evaluation" | A condition that is too strict, a typo in a criterion, or data that changed |
| Output area is occupied | `#REF!` with "Array result was not expanded because it would overwrite data in F5" | A value, a space, or another formula sits in the spill range |
| Condition range has a different size | `#VALUE!` with "FILTER has mismatched range sizes" | Ranges such as `A2:D100` and `C2:C99` |
You can see the message by clicking the formula cell and hovering over the red triangle. The message names the exact cell that blocks the output, which makes it the fastest clue.
Handle a FILTER with no matches
Take a sheet with Region in column A, Rep in B, Amount in C and Date in D. This formula returns every row where Amount is at least 1000:
=FILTER(A2:D, C2:C>=1000)If no Amount reaches 1000, the cell shows #N/A. That is correct behavior, but it looks like a failure. The usual fix is to wrap the formula in IFERROR, which returns a value of your choice when the inner formula errors:
=IFERROR(FILTER(A2:D, C2:C>=1000), "No matches")When rows match, you get the normal table. When none match, the single cell shows the text "No matches". If your formula also sorts, put IFERROR on the outside so it covers the whole chain:
=IFERROR(SORT(FILTER(A2:D, C2:C>=1000), 3, FALSE), "No matches")SORT receives the #N/A from FILTER and passes it up. The outer IFERROR then replaces it. If you put IFERROR only around SORT's result in some other way, or inside FILTER, it may not catch the error you expect.
Show a blank instead of a message
Sometimes you want the area to stay empty, for example when other formulas read from it. Return an empty string:
=IFERROR(FILTER(A2:D, C2:C>=1000), "")An empty string looks blank, but the cell is technically not empty. A later COUNTA over that cell counts it. Keep this in mind if you count results.
IFERROR is broad: prefer a narrower check
IFERROR catches every error, not only "no matches". If you misspell a range, or the source contains a #DIV/0!, the sheet will still say "No matches". That message is false and hides the real problem.
You have two safer options.
- Use
IFNA, which catches only#N/A. The no-match error fromFILTERis#N/A, so this is a closer fit:
=IFNA(FILTER(A2:D, A2:A="West", C2:C>1000), "No matches")- Test for matches first, and run
FILTERonly if any exist:
=IF(COUNTIFS(A2:A, "West", C2:C, ">1000")=0, "No matches", FILTER(A2:D, A2:A="West", C2:C>1000))The second form repeats your conditions in two syntaxes, so it is easier to get out of sync when you edit one. Use it when the exact wording of the error matters, such as in a shared report. Use IFNA for everyday work.
Note that IFNA still passes through #VALUE! and #REF!, and that is the point. Those errors mean something is wrong with the formula or the layout, so you want to see them.
Keep the message from looking like data
A text message in the first cell of the output area can be mistaken for a result row. Two habits help:
- Put the formula in a labeled area, such as a heading in the row above it.
- Format the output cell in a muted color or italic style, so a message is clearly different from data.
Understand blocked output ranges
When a formula returns five rows and four columns, Sheets needs those twenty cells to be free, starting at the formula cell. If any one of them already holds content, the whole formula fails with #REF!. It does not fill part of the area.
Suppose you put this in F2:
=SORT(A2:D, 3, FALSE)The result needs F2:I down to the last data row. If G6 contains the number 5, the formula in F2 shows:
#REF! Array result was not expanded because it would overwrite data in G6.
Sheets reports only one blocking cell, even if several exist. After you clear it, a new error may point to the next one.
What counts as "data"
- Typed values, including a single space. A space is invisible, so a cell can look empty and still block the output.
- Another formula, including one that returns an empty string
"". - A result from a second array formula whose spill range overlaps this one.
- Cells that the formula would have used when the source grew. A formula can work today and fail next month when new rows push the result into a cell below it.
The last point is the one that surprises people. The spill range depends on the number of rows returned, and that number follows the source data. Any cell you place below the formula is a risk.
Fix a blocked range
- Click the formula cell and read the error. Note the cell it names.
- Go to that cell. Select it and press Delete. If the cell looks empty, select the whole column below the formula and check for stray spaces.
- If the content is needed, move it. Place it to the side of the output, not under it.
- Check again. If the error names a new cell, repeat.
To clear a region quickly, select the cells below and to the right of the formula and use Edit > Delete > Values, or select the rows and choose Clear. Do not select the formula cell itself, or you will delete the formula.
Design layouts that cannot be blocked
The best fix is a layout that avoids the problem:
- Put each array formula on its own sheet, or leave everything below it empty.
- Place several array formulas side by side with at least one empty column between them, never stacked vertically.
- Use a full open-ended range such as
A2:D, not a fixedA2:D100, so new rows are included and the output size follows the data. Then keep the area below the formula free. - Put totals above the output, not below. A summary row below a growing result will eventually collide with it.
=SORT(UNIQUE(A2:A))This formula, placed in a column of its own, can grow downward freely. A note in the cell directly beneath it would stop it as soon as a second region appears.
Mismatched range sizes
FILTER requires every condition range to have the same number of rows as the data range. This formula fails because the ranges differ by one row:
=FILTER(A2:D100, C2:C99>1000)The result is #VALUE! with a message that gives the expected and actual row counts. This error is not caught by IFNA, which is why you should not hide it with IFERROR. Fix it by making the ranges equal, or use open-ended ranges for both, as in A2:D and C2:C.
A diagnosis flow
When a FILTER or SORT cell shows an error, check these questions in order.
Common mistakes
- Wrapping with
IFERRORtoo early. The message "No matches" then hides typos and layout problems. UseIFNAunless you really want every error replaced. - Treating
""as empty. A blank string returned byIFERRORstill counts inCOUNTA. UseCOUNTIF(range, "?*")orROWSon the result with care. - Placing notes below a result. The result works now and breaks when the data grows.
- Fixing a blocked range by typing over the formula. The error names a cell that holds other content. Clear that cell, not the formula.
- Expecting a partial result. A blocked range gives no output at all, not a truncated one.
Practice
Exercise
A cell contains =IFERROR(FILTER(A2:D, A2:A="West", C2:C>1000), "No matches") and shows "No matches", but you know West has large sales. You then change the formula to =FILTER(A2:D, A2:A="West", C2:C>1000) and see #REF! with the message "Array result was not expanded because it would overwrite data in G9." What was wrong, and what do you do?
Show answer
The result was blocked, not empty. IFERROR replaced the #REF! error with "No matches", which made the failure look like an empty result. Cell G9 holds a value, a space, or another formula that sits inside the spill range. Clear or move G9, and check the column below for other content. Then use IFNA instead of IFERROR so a blocked range stays visible while true no-match results still show the message.
Exercise
Write a formula that returns all rows of A2:D where Region is "East" and shows the text "Nothing found" only when there are no such rows, without hiding other kinds of errors.
Show answer
=IFNA(FILTER(A2:D, A2:A="East"), "Nothing found")