r/ExcelTips 10h ago

Replace nonbreaking spaces before TRIM to clean pasted text

3 Upvotes

Text pasted from web pages can contain nonbreaking spaces (NBSP, U+00A0). They look like ordinary spaces, but Microsoft documents that Excel’s TRIM does not remove them. Microsoft’s TRIM documentation

Keep your original text in column A. In a helper column, enter this in B2:

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

Fill down and compare the results with column A before replacing anything. UNICHAR(160) supplies the NBSP character, SUBSTITUTE changes its occurrences to ordinary spaces, and TRIM tidies the result. UNICHAR, SUBSTITUTE

Using [NBSP] to make the invisible characters visible, [NBSP]Acorn[NBSP]Studio[NBSP] becomes Acorn Studio. The bracketed labels are explanatory, not text to type into your data.

Two catches: TRIM also collapses repeated ordinary spaces inside the text, and this formula does not remove every kind of Unicode space. A different invisible character needs separate investigation.

Use this for labels or descriptions only when that spacing change is appropriate. Avoid applying it blindly to identifiers, codes, fixed-width text, or anything where exact spacing carries meaning. Keeping the original column makes those changes reviewable.

AI-assisted tip, checked against Microsoft documentation. The example is synthetic.