Sub topic 1
Cleaning Messy Data in Google Sheets with Trim, Dedupe, and Split Tools
Prerequisites
This chapter assumes you know rows, columns, cells, and ranges in Google Sheets. You should be able to enter a simple formula such as =A1&B1, select a range, and use the menu bar.
What messy data looks like
Imported and hand-typed data often contains small errors that look harmless. Common problems include:
- Extra spaces at the start or end of a value, or repeated between words, such as " Jane Doe ".
- Invisible characters, such as non-breaking spaces copied from web pages.
- Inconsistent capitalization, such as "jane doe" and "Jane Doe".
- Repeated rows created by copying, pasting, or re-importing.
- Combined values, such as "Doe, Jane" stored in one cell.
These problems break lookups, counts, and pivot tables. A VLOOKUP for "Jane Doe" fails against "Jane Doe " because the trailing space makes the text different.
Protect the original
Before you change anything, make a copy of the sheet. Right-click the sheet tab and choose Duplicate. Do all cleanup on the copy so you can compare results against the raw data and recover if a step goes wrong.
Remove extra spaces with Trim whitespace
Select the column to clean, then choose Data > Data cleanup > Trim whitespace. Sheets removes leading, trailing, and repeated spaces in the selected cells. This edits the values in place, so run it only on the copy.
Trim with a formula: the TRIM function
TRIM is a function that returns cleaned text and leaves the source cell unchanged. Enter it in a new column:
=TRIM(A2)To clean a whole column with one formula, wrap it in ARRAYFORMULA:
=ARRAYFORMULA(TRIM(A2:A))TRIM does not remove non-breaking spaces. You need CLEAN and SUBSTITUTE for those, which a later chapter covers.
Exercise
Cell A2 contains " Jane Doe ". What does =TRIM(A2) return?
Show answer
"Jane Doe". TRIM removes the leading and trailing spaces and reduces the three spaces between the names to one.