Sub topic 2
Invisible characters TRIM misses: CLEAN and non-breaking spaces
Prerequisites
This chapter assumes you can enter a formula, fill it down a column, and open the Data menu. You should already know that TRIM removes extra spaces.
Why TRIM is not enough
TRIM removes ordinary spaces at the start and end of a cell, and it collapses runs of spaces between words into one. It leaves two kinds of hidden characters in place:
- Non-printing characters, such as line breaks and tabs, which CLEAN removes.
- Non-breaking spaces (character code 160), which look like spaces but which TRIM ignores.
A cell holding "Jane Doe" with a non-breaking space looks clean, yet a lookup for "Jane Doe" fails against it.
Remove hidden characters
Replace non-breaking spaces first, then clean and trim the text:
=TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " ")))To apply the formula to a whole column, wrap it in ARRAYFORMULA:
=ARRAYFORMULA(TRIM(CLEAN(SUBSTITUTE(A2:A, CHAR(160), " "))))Make capitalization consistent
- LOWER converts every letter to lowercase.
- UPPER converts every letter to uppercase.
- PROPER capitalizes the first letter of each word and lowercases the rest.
=ARRAYFORMULA(PROPER(TRIM(A2:A)))This turns " jANE doe " into "Jane Doe". PROPER also lowercases letters inside a word, so "McDonald" becomes "Mcdonald". Check unusual names before you apply PROPER to them.
Remove duplicate rows with the Remove duplicates tool
- Select the data range, including the header row.
- Choose Data > Data cleanup > Remove duplicates.
- Choose the columns to compare and confirm the header row setting.
- Click Remove duplicates.
> Work on a copy of the sheet first. Removing rows changes the data in place.
Review duplicates with COUNTIF before deleting
Enter this in a helper column next to your data, then fill it down:
=COUNTIF($A$2:A2, A2) > 1The formula returns TRUE for each repeat after the first occurrence. Filter on TRUE to review the rows, then delete them.
Deduplicate with UNIQUE
=UNIQUE(A2:C)UNIQUE writes its distinct rows to a new location and leaves the source data unchanged. The result spills downward, so the cells below the formula must be empty.
Exercise
Exercise
Cell A2 contains "Jane Doe" with a non-breaking space between the words. Which formula returns "Jane Doe" with a normal space?
Show answer
=TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " ")))