Sub topic 13
Pitfalls: blocked spill ranges, whitespace, and escaping
Assume you can enter formulas, reference cells and ranges, and use basic functions such as TRIM and IFERROR. This chapter focuses on diagnosing formulas that produce unexpected results rather than on introducing SPLIT, JOIN, or REGEXEXTRACT.
Blocked spill ranges
A spill range is the group of cells that a formula fills automatically. SPLIT can spill pieces across columns. REGEXEXTRACT can spill capture groups across columns. An ARRAYFORMULA can spill results across several rows.
Every cell that the result needs must be empty. If one cell contains text, a number, a formula, or sometimes a merged-cell layout, Sheets cannot expand the result. It displays an error such as “Array result was not expanded because it would overwrite data.”
Before changing the formula, inspect the cells to the right and below the formula. Delete unwanted contents, move the formula, or choose a larger empty area. Do not merely hide the blocking value. A hidden value still occupies the cell.
A capture-group formula has the same requirement:
=REGEXEXTRACT(A2, "([A-Z]+)-(\\d+)")The result needs two adjacent cells. If the first group returns ORD and the second returns 10492, both cells must be available.
Whitespace after splitting
SPLIT uses the delimiter you provide, but it does not automatically remove spaces surrounding each piece. For example, splitting red; blue; green at the semicolon produces pieces beginning with spaces.
=ARRAYFORMULA(TRIM(SPLIT(A2, ";")))TRIM removes leading and trailing spaces from each spilled value. It also reduces repeated ordinary spaces inside text. If imported data contains non-breaking spaces, which look like ordinary spaces but use a different character, TRIM may not remove them. Replace character 160 first:
=ARRAYFORMULA(TRIM(SUBSTITUTE(SPLIT(A2, ";"), CHAR(160), " ")))A delimiter can also create empty pieces. For example, a value such as red;;green has nothing between the two semicolons. The fourth SPLIT argument controls this behavior:
=SPLIT(A2, ";", TRUE, FALSE)Here, FALSE preserves empty pieces. Use TRUE when you want empty pieces removed. Be deliberate, because removing them changes the position of later values.
Escaping regular expressions
REGEXEXTRACT uses RE2 regular expression syntax. Some characters have special meanings:
- A period means “any character.” Use
\.to match an actual period. - A plus sign means “one or more of the preceding item.”
- Parentheses create a capture group.
- Square brackets define a character set.
- A backslash introduces a shortcut or escapes a special character.
For an email-like value, the period between the domain and suffix must be escaped:
=REGEXEXTRACT(A2, "[\w.+-]+@[\w-]+\.[\w.]+")SPLIT does not interpret its delimiter as a regular expression. In SPLIT, a period is simply a period. Do not add regex escaping there unless the actual text contains a backslash.
Formula strings also use double quotation marks. If a pattern must match a literal quotation mark, constructing it with CHAR(34) can make the formula easier to read:
=REGEXEXTRACT(A2, "name="&CHAR(34)&"([^"&CHAR(34)&"]+)"&CHAR(34))This pattern extracts the value inside name="...".
A troubleshooting checklist
| Symptom | Likely cause | Practical fix |
|---|---|---|
| Spill error | A target cell is occupied | Clear or move the target area |
| Pieces contain leading spaces | The delimiter is not the whitespace | Wrap SPLIT with TRIM |
| A period matches too much text | The period is a regex wildcard | Use `\.` in REGEXEXTRACT |
| Output positions shift | Empty pieces were removed | Set remove_empty_text to FALSE |
| REGEXEXTRACT returns #N/A | No substring matches | Test the pattern or use IFERROR |
Exercise
A2 contains ORD-10492 , and B2 already contains a note. You need the letters and digits in separate cells. What should you check and what formula can you use?
Show answer
Check that the cells needed for the two-column result are empty, then use =REGEXEXTRACT(TRIM(A2), "([A-Z]+)-(\\d+)") in an available cell.