New Tool Radar

AI for Data & Spreadsheets

How to Remove Extra and Non-Breaking Spaces in Excel With TRIM and CLEAN

Strip leading, trailing and doubled spaces, plus non-breaking spaces and hidden characters, so lookups and totals work again.

Schematic with three steps: Find the hidden characters with LEN; Clean with TRIM, CLEAN and SUBSTITUTE together; Paste as values and re-test the lookup.

Two values can look identical and still fail a lookup because one has a trailing space, or a non-breaking space copied from a web page. TRIM removes ordinary spaces, CLEAN removes control characters, and SUBSTITUTE handles the non-breaking space that TRIM cannot see.

What you need

  • Excel with the messy text column
  • An empty helper column beside the data
  • A note of how long a clean value should be

Step 1: Find the hidden characters with LEN

In a helper column, enter =LEN(A2) and compare the length with the characters you can see. A longer length means hidden spaces or characters are present, even though the cell looks clean.

Step 2: Clean with TRIM, CLEAN and SUBSTITUTE together

In the helper column, enter =TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160),’ ‘))) and fill it down. SUBSTITUTE replaces non-breaking spaces with ordinary ones first, CLEAN removes control characters, and TRIM removes the extra spaces.

Step 3: Paste as values and re-test the lookup

Copy the cleaned column and use Paste Special, Values, over the original or beside it. Re-run the lookup that failed before; it should now match, and the LEN values should equal the visible length.

Worked example: synthetic four-row sample register

The table below is a synthetic example. It shows the expected result of cleaning spaces; no workbook was opened.

Row Length before Length after Lookup
Row 2 18 16 Matches
Row 3 17 16 Matches
Row 4 19 16 Matches
Row 5 16 16 Matches

Expected result (UNTESTED). all four IDs clean to 16 characters and all four lookups now match. Row 4 needed SUBSTITUTE for its non-breaking space, which TRIM alone could not remove. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • TRIM only removes the ordinary space, character 32; it leaves the non-breaking space, character 160, untouched.
  • CLEAN deletes line breaks rather than replacing them with a space, so two lines can join into one word.
  • Clean both sides of a lookup: the lookup value and the lookup table need the same treatment.

Sources

See all