Excel templates and practical guides

Excel problem solving

TRIM Not Working in Excel? Find and Remove Hidden Spaces

Auditably.co · Published 29 November 2026 · 3 minute read

If TRIM leaves a gap that looks like a space, the character may not be an ordinary space. Text copied from websites, PDFs and other systems can contain nonbreaking spaces, line breaks or invisible characters that look similar on screen.

Do not repeatedly apply the same formula and hope the result changes. Keep the original text, identify the character and apply a targeted replacement in a helper column. The practice workbook includes six deliberately different examples.

In this guide
Hidden spaces practice: actual workbook preview with fictional example entries
Actual preview of the Spaces sheet. Open the full-size image to inspect the figures.

What TRIM removes, and what it misses

Microsoft documents that TRIM targets the ordinary space character, code 32. It does not, by itself, remove the nonbreaking space with code 160. It also reduces repeated ordinary spaces inside text to a single space, which may be unsuitable for fixed-width records.

Character Decimal code Useful action for ordinary prose
Ordinary space 32 TRIM leading, trailing and repeated spaces
Nonbreaking space 160 Replace with an ordinary space, then TRIM
Narrow nonbreaking space 8239 Replace with an ordinary space if appropriate
Zero-width space 8203 Remove only when it is unwanted
Line feed 10 Replace with a space if joining lines
Tab 9 Replace with a space if joining fields

These are selected cases, not a complete list of Unicode whitespace. The correct treatment depends on whether you are cleaning a name, a paragraph, an identifier or a structured export.

Find the character first

Use LEN(A2) to see how many characters are present. Two cells that look identical may have different lengths. To inspect the first character, use:

=UNICODE(LEFT(A2,1))

For a suspicious character inside the string, choose its position with MID. This inspects character 6:

=UNICODE(MID(A2,6,1))

The first-character formula is only a starting point. It will not diagnose an invisible character in the middle of a cell. Move the position through the text or compare a short known sample.

Fix nonbreaking spaces

For code 160, replace it with an ordinary space and then trim:

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

Replacing it with an empty string could join words. North office should usually become North office, not Northoffice.

For a narrow nonbreaking space, use UNICHAR:

=TRIM(SUBSTITUTE(A2,UNICHAR(8239)," "))

Handle zero-width characters and line breaks differently

A zero-width space can be removed with:

=SUBSTITUTE(A2,UNICHAR(8203),"")

That is appropriate only when you want the surrounding characters joined. In the workbook, North followed by a zero-width space and office becomes Northoffice. The result deliberately shows why cleaning cannot decide the intended wording for you.

For a line break separating words, replace character 10 with a space instead. CLEAN can remove certain control characters, but removing a separator may concatenate words. Inspect the result before replacing the source column.

Use the practice workbook

Open the Spaces sheet. Column B contains the original strings, C shows their lengths, D shows TRIM alone, E reports the first character code and F applies the selected replacements. Compare D and F for the nonbreaking-space example.

The combined helper handles the six cases shown. It is not a universal “remove invisible characters” formula. Preserve punctuation, spacing and characters that matter to your data, especially product IDs and multilingual text.

When the cleaned result is correct, copy and paste values into a new output column if you need a fixed export. Retain the original and document the rule. If a lookup still fails, also check data type, case requirements and whether the two records truly use the same identifier.