Sub topic 5
Invisible Characters TRIM Misses: CLEAN and Non-Breaking Spaces
Assume you know how to select a range and enter a basic Google Sheets formula. In this chapter, you will clean text that looks normal but behaves differently in searches, lookups, and duplicate checks.
Why TRIM is not enough
TRIM removes ordinary leading and trailing spaces. It also changes repeated ordinary spaces between words into one space. However, copied text can contain characters that look like spaces but are not ordinary spaces.
Two common problems are:
- Non-printing characters, such as line breaks or control characters copied from another system.
- Non-breaking spaces, which keep words together in web pages and documents.
These characters can make two values appear identical while Google Sheets treats them as different.
For example, a customer name with a non-breaking space may fail to match the same name typed directly into another cell. A duplicate check can also miss it.
How CLEAN and SUBSTITUTE work
CLEAN removes many non-printing characters from text. It is useful for text imported from older systems or copied from formatted documents.
SUBSTITUTE replaces one piece of text with another. In this case, use CHAR(160) to represent a non-breaking space and replace it with an ordinary space.
The following formula combines both operations with TRIM:
=TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " ")))The operations happen from the inside out:
SUBSTITUTEchanges non-breaking spaces into ordinary spaces.CLEANremoves non-printing characters.TRIMremoves extra ordinary spaces.
Put the formula in a helper column beside the original value. Then fill it down. Review the results before replacing the original column.
Clean a whole column with ARRAYFORMULA
If column A contains imported names, place this formula in an empty column, such as B2:
=ARRAYFORMULA(TRIM(CLEAN(SUBSTITUTE(A2:A, CHAR(160), " "))))ARRAYFORMULA applies the calculation to the range instead of requiring a separate formula in every row. The result spills into the cells below it.
This formula is useful before:
- Comparing values with
COUNTIForVLOOKUP. - Checking for duplicates.
- Splitting a combined value into columns.
- Standardizing capitalization with
PROPER.
You can combine cleanup with capitalization when names need a consistent display format:
=ARRAYFORMULA(PROPER(TRIM(CLEAN(SUBSTITUTE(A2:A, CHAR(160), " ")))))Use capitalization only when it is appropriate. PROPER can change names or codes in unwanted ways, especially when they contain abbreviations.
A practical cleanup flow
| Symptom | Likely cause | Useful response |
|---|---|---|
| Values look equal but do not match | Non-breaking space | `SUBSTITUTE(..., CHAR(160), " ")` |
| Text contains copied line breaks or control characters | Non-printing character | `CLEAN` |
| Words have inconsistent spacing | Ordinary extra spaces | `TRIM` |
After cleaning, verify a few rows manually. Compare the cleaned value with the original, and test a lookup or duplicate check that previously failed. Keep the original column until you confirm that the cleaned result preserves the information you need.
Exercise
Which formula removes non-breaking spaces, non-printing characters, and extra ordinary spaces from A2?
Show answer
=TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " ")))