Sub topic 3
Remove Extra Spaces with Trim Whitespace
This chapter assumes you can select ranges, use the Google Sheets menu bar, and enter simple formulas such as =A1&B1. You will clean spaces in a copied data range without changing the original import.
Why extra spaces cause problems
Messy text often contains spaces that are difficult to see:
- A leading space appears before a value, such as
Jane Doe. - A trailing space appears after a value, such as
Jane Doe. - Several spaces appear between words, such as
Jane Doe.
These differences matter because Google Sheets compares text exactly in many operations. A lookup, filter, count, or sort can treat Jane Doe and Jane Doe as different values.
The Trim whitespace command removes leading and trailing spaces. It also changes repeated spaces between words into one space.
| Before cleanup | After Trim whitespace |
|---|---|
| ` Jane Doe ` | `Jane Doe` |
| `Seattle ` | `Seattle` |
| ` West Region` | `West Region` |
Protect the source range
Before using a cleanup command, preserve the imported data. Make a copy of the sheet or duplicate the relevant tab. The Trim whitespace command changes the selected cells directly, so it does not leave the original values available for comparison.
A safe workflow is:
- Duplicate the source tab.
- Rename the copy, such as
Customers - cleaned. - Select only the data range that should be cleaned.
- Run Trim whitespace on the copy.
Avoid selecting the entire sheet unless you know that every cell should be changed. Cleaning empty cells is harmless in most cases, but selecting unrelated notes or formulas can produce unwanted changes.
Use Data cleanup > Trim whitespace
Try the command with a small range first.
- Select the cells containing the text. Include the header only if you also want to clean the header.
- Open the Data menu.
- Choose Data cleanup.
- Select Trim whitespace.
- Inspect the changed values.
For example, suppose column A contains customer names from A2:A6. Select that range and apply the command. A value such as jANE doe will become jANE doe. Trim whitespace changes spacing only. It does not standardize capitalization.
=TRIM(A2)The formula equivalent is useful when you want to keep the original range unchanged or make the cleanup repeatable. The TRIM function removes leading and trailing spaces and reduces repeated spaces between words. In this chapter, the menu command is the quickest choice for a one-time edit.
Understand what the command changes
The command changes cell contents, not the width of columns or the visual alignment of numbers. It is intended for text values. It also does not:
- Change uppercase or lowercase letters.
- Remove punctuation.
- Split one cell into multiple columns.
- Decide whether two rows are duplicates.
- Remove blank rows.
Use the command before matching or deduplicating text, because consistent spacing makes those later operations more reliable.
Check the result
Compare several cells before and after the cleanup. Check a value with spaces at the beginning, one with spaces at the end, and one with repeated spaces between words. If formulas or lookups depend on the range, test one of those operations again.
Remember that visual inspection is not always enough. A cell can look correct while still containing a non-breaking space or another hidden character. Those cases require the cleanup methods covered later.
Exercise
A selected range contains North Zone and North Zone. What will Trim whitespace do to each value, and will it remove duplicate rows?
Show answer
It changes both values to North Zone, but it does not remove duplicate rows. Use a duplicate-removal tool or a formula after checking the cleaned data.