Sub topic 10
Handling Rows with No Match Using IFERROR
This chapter assumes you can enter Google Sheets formulas, reference cells and ranges, and use functions such as REGEXEXTRACT, TRIM, and IFERROR. You should also know that text values are strings and that a formula can return an error instead of a normal value.
REGEXEXTRACT returns the first part of a cell that matches a regular expression. When no match exists, it returns a #N/A error. This is expected behavior, but an error can make a cleaned data column difficult to read or use.
IFERROR lets you replace an error with a value you choose:
=IFERROR(value, value_if_error)The first argument is the formula to evaluate. The second argument is returned if that formula produces an error.
Replacing a no-match error
Suppose column A contains messages, and you want to extract a number from each message. A message may contain a number, or it may not.
| A | B |
|---|---|
| Order ORD-10492 shipped | 10492 |
| No order number assigned | No order ID |
| Order ORD-10501 delayed | 10501 |
In B2, use:
=IFERROR(REGEXEXTRACT(A2, "\d+"), "No order ID")For the first row, REGEXEXTRACT finds 10492, so IFERROR returns that match. For the second row, the regular expression finds nothing, so IFERROR returns No order ID.
The fallback can be text, a blank string, zero, or another formula.
=IFERROR(REGEXEXTRACT(A2, "\d+"), "")This version leaves the result blank when no digits exist. A blank is useful when another formula will process the column later.
=IFERROR(VALUE(REGEXEXTRACT(A2, "\d+")), 0)This version returns a number when digits are found and 0 when they are not. Because REGEXEXTRACT returns text, VALUE converts the match before calculations use it.
Understanding what the error wrapper covers
IFERROR catches any error produced by its first argument, not only a missing regular-expression match. For example, it also catches an invalid reference or a conversion error.
=IFERROR(VALUE(REGEXEXTRACT(A2, "\d+")), "Check row")This is convenient for a display column, but it can hide unexpected problems. If every row suddenly says Check row, inspect the original formula and sample data instead of assuming that every row simply lacks digits.
Use a specific fallback that helps you diagnose the data:
=IFERROR(REGEXEXTRACT(A2, "[\w.+-]+@[\w-]+\.[\w.]+"), "Missing email")This separates a normal missing value from a formula or data problem only when the surrounding formula is known to be valid.
Applying the pattern to a column
You can handle several rows with one formula by combining ARRAYFORMULA and IFERROR:
=ARRAYFORMULA(IFERROR(REGEXEXTRACT(A2:A10, "\d+"), "No number"))The formula evaluates the range and spills one result per input row. Keep the cells below and beside the formula empty so the result can spill.
The model looks like this:
Choosing a fallback
| Situation | Formula pattern | Result when no match exists |
|---|---|---|
| Display a clear label | `=IFERROR(REGEXEXTRACT(A2, "\d+"), "Missing")` | `Missing` |
| Keep the output visually clean | `=IFERROR(REGEXEXTRACT(A2, "\d+"), "")` | Blank |
| Use the result in arithmetic | `=IFERROR(VALUE(REGEXEXTRACT(A2, "\d+")), 0)` | `0` |
Choose a fallback that preserves the meaning of the column. A blank means “not shown,” while zero means “the numeric value is zero.” Those meanings are different.
Exercise
Write a formula that extracts an email address from A2 and returns a blank when A2 contains no email-like text.
Show answer
=IFERROR(REGEXEXTRACT(A2, "[\w.+-]+@[\w-]+\.[\w.]+"), "")