Text cleanup

How to Remove Extra Spaces in Excel (TRIM, CLEAN and Non-Breaking Spaces)

By the DecodingPro teamUpdated 3 min read

Quick answer

Use =TRIM(A2) to remove spaces at the start and end and reduce repeated spaces between words to one. If the text still looks wrong, it contains non-breaking spaces or invisible characters, which TRIM ignores. Use =TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," "))) instead.

Extra spaces make "John Smith" and "John Smith " look identical and behave differently. Lookups fail, duplicates are missed, sorting puts the odd one out and emails bounce. This guide shows how to remove every kind of stray space.

Step 1: TRIM for ordinary spaces

=TRIM(A2)

TRIM removes leading and trailing spaces and replaces any run of spaces between words with a single space. Fill the formula down, copy the results, and Paste Special, Values, over the original column.

Step 2: the space TRIM cannot see

Web pages, PDFs and many exports use a non-breaking space, character 160. It looks like a space but TRIM only removes the normal space (character 32), so the text seems untouched. Replace it first:

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

To test whether a cell has one: =ISNUMBER(FIND(CHAR(160),A2)).

Step 3: CLEAN for invisible characters

Line breaks and other non-printing characters (the first 32 characters of the ASCII table) can hide in imported text. CLEAN removes them:

=CLEAN(A2)

The combined formula for everything above:

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

Where each tool helps

SymptomCauseUse
Space before or after the textTyped or pasted with spacesTRIM
Two spaces between wordsCareless typingTRIM
TRIM does nothing, but the length is too longNon-breaking spaceSUBSTITUTE with CHAR(160)
Words run together or the text jumps linesLine break inside the cellCLEAN, or SUBSTITUTE with CHAR(10)
A strange box or question markNon-printing characterCLEAN

To see how many characters a cell really has, compare =LEN(A2) with =LEN(TRIM(A2)): any difference is stray spaces.

Find and Replace for a quick fix

Press Ctrl+H. In "Find what", type two spaces; in "Replace with", type one space; click Replace All, and repeat until nothing changes. This does not remove spaces at the start or end of a cell, so TRIM is better.

Warning: do not remove all spaces from columns where they matter, such as names ("Mary Ann") or addresses. Only remove the extra ones.

Spaces inside numbers and phone numbers

1 234 is text, not a number, until the space goes: =VALUE(SUBSTITUTE(A2," ","")). For phone numbers, see fixing phone numbers in Excel, because removing every space is only part of that job.

A whole file at once

DecodingPro trims every text cell in the file, handles the non-breaking spaces, and lists every change so you can see exactly what was touched.

Try it on your own file

You start with 100 free credits. Every change is logged, and anything unclear is flagged, never guessed.

Fix a spreadsheet

Questions people ask

Why is TRIM not working on my data?

The spaces are probably non-breaking spaces (character 160) copied from a website or PDF. Wrap the cell in SUBSTITUTE(A2,CHAR(160)," ") before TRIM.

Does TRIM change numbers?

It turns a number into text, because the result of TRIM is always text. Use VALUE around it if you need a number back.

Can TRIM remove a line break?

No. Use CLEAN, or SUBSTITUTE(A2,CHAR(10)," ") to replace the line break with a space.

Keep reading

01Excel data cleaningHow to Clean Messy Excel Data: A Step-by-Step GuideThe fixed order that stops one fix from undoing another, with the formulas for every step.10 min read02Text and numbersHow to Keep Leading Zeros in Excel and CSV (ZIP Codes, IDs)Why Excel turns 02134 into 2134, how to get the zeros back, and how to stop it happening when you open a CSV.5 min read03CSV and importsHow to Clean a CSV File Before Importing It Into a CRMSeven fixes that prevent duplicate contacts, rejected rows and scrambled characters, and the 10-row test to run first.4 min read04DatesHow to Fix Dates in Excel and CSV Files (Mixed Formats)Text dates, day-month swaps, two-digit years and the one rule that makes dates safe to share.8 min read05Phone numbersHow to Fix Phone Numbers in Excel: Format and Country CodesLeading zeros, 9.19E+11, country codes and the international format that every system accepts.6 min read06DuplicatesHow to Remove Duplicates in Excel Without Losing DataExact, near and partial duplicates: decide what counts, mark before you delete, keep the best record.6 min read07DuplicatesHow to Find and Highlight Duplicates in ExcelFind repeats safely first: highlight them, count them, keep the first one, and spot the near-duplicates Excel does not see.3 min read08NamesHow to Standardize Names in Excel: Proper Case and ExceptionsWhat PROPER gets wrong, how to protect names that are already right, and how to flip "Smith, John" into "John Smith".4 min read09Email addressesHow to Fix Email Typos in Excel: gmial.com, .con and Missing @The typos that make campaigns bounce, and the formulas and checks that fix them without guessing.4 min read10Email addressesHow to Clean an Email List Before You Send a CampaignA five-step routine that removes the avoidable bounces from a list without deleting anyone you should keep.3 min read11NamesHow to Split Full Names into First and Last Name in ExcelFlash Fill, Text to Columns and formulas for splitting names, and the names that trip each one up.4 min read13Text cleanupHow to Remove Special Characters and Line Breaks in ExcelThe characters you cannot see, the smart quotes you can, and the exact formula or shortcut that removes each one.4 min read14NumbersHow to Convert Text to Numbers in Excel (Numbers Stored as Text)Why sums show zero, why numbers sit on the left, and four ways to turn text back into real numbers.3 min read15Excel data cleaningHow to Clean Data with Power Query in Excel (Step by Step)Record your cleaning steps once and replay them on every new file, without formulas and without touching the original data.4 min read16Comparing dataHow to Compare Two Lists in Excel and Find What Is MissingFind the names, IDs or emails that are in one list and not the other, with formulas that scale.3 min read17CSV and importsFix Garbled Characters and Broken CSV Imports (UTF-8)UTF-8, delimiters, leading zeros, quotes and a checklist that makes a file safe to import.7 min read18Data entryData Entry Accuracy: How to Check, Measure and Improve ItWhat the research says about error rates, why proofreading fails and the checks that actually work.9 min read