Practice problems / Data Cleaning

Clean extra spaces from imported names (TRIM)

Easy Data Cleaning
Description
Hints 0/4
Solutions 2
–
Test case
1
2
3
Reset
Submit
fx
A
B
C
D
E
F
G
1
2
3
4
5
6
7
8
9
10
Loading interactive spreadsheet...
Preparing grid cells and formula calculation engine
○ Ready Enter formula in highlighted cells, then click Submit.

The problem

Problem statement

A CRM export landed in your inbox, and every customer name carries stray spaces — leading, trailing, even doubles in the middle. Your mail merge will bounce on all of them. Fill the Cleaned name cells C2:C5 so each name from A2:A5 is trimmed to a single normal form.

TRIM also collapses inner double spaces — case 3 is already clean and must come back unchanged.

Problem data

Show the sheet as a table (selectable, copyable)
The exercise data, as a table
AC
1 Imported nameCleaned name
2 Anna Lee
3 Ben Wang
4 Cara Diaz
5 Dan Wu

Notes

TRIM removes leading and trailing spaces and collapses internal runs of spaces to a single space. It does not remove non-breaking spaces (CHAR(160)) from web data — SUBSTITUTE handles those.

How to approach

Your answer goes in C2:C5. On submit we re-run your formula against 3 different sets of input, so a hardcoded number will fail — the formula has to follow the cells.

  1. Target cells are C2:C5 — start in C2, then fill down
  2. The dirty text is in A2
  3. One function does all the space cleanup on its own
  4. It takes a single argument: the text to clean

Official solutions

Show 2 solutions — try it yourself first

Approach 1: Plain TRIM

=TRIM(A2)

TRIM strips leading/trailing spaces and squeezes middle space runs down to one. " Anna Lee " becomes "Anna Lee". Fill down through C5.

Approach 2: TRIM + SUBSTITUTE for non-breaking spaces

=TRIM(SUBSTITUTE(A2, CHAR(160), " "))

Web-scraped data often hides non-breaking spaces that TRIM ignores. Swapping them for normal spaces first makes TRIM fully effective.

Function guide

Related practice

FAQ

How do I remove extra spaces in Excel?

Use =TRIM(A2). It deletes leading and trailing spaces and reduces any run of inner spaces to a single space.

Why do some spaces survive TRIM?

TRIM only handles the standard space character. Non-breaking spaces (CHAR(160)) from web pages survive it — wrap the text in SUBSTITUTE(text, CHAR(160), " ") first.

Can I TRIM a whole column at once?

Write =TRIM(A2) in C2, then fill down (or double-click the fill handle) so every row gets a cleaned copy next to it.