How to remove extra spaces from text in Excel
Formula (Excel and Google Sheets)
=TRIM(A2)Use =TRIM(A2). It removes spaces at the start and end and turns runs of spaces between words into one.
- Result on the example
- one result per row in
B2, filled down toB6 - Works in
- Every current version
- Google Sheets
- Same formula
See it work
The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.
How it works
TRIM strips leading and trailing spaces and collapses repeated spaces inside the text to a single space. Extra spaces are the most common reason a lookup returns #N/A for a value you can see.
=TRIM(A2)Result"Maria Lopez"
A2" Maria Lopez"The value in A2.
TRIM(A2)"Maria Lopez"TRIM: Removes extra spaces, leaving single spaces between words.- text
A2" Maria Lopez"
- text
In Google Sheets
The same formula works in Google Sheets: =TRIM(A2). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =TRIM(CLEAN(A2)) | Maria Lopez, James O'Neil, Aiko Tanaka… | CLEAN also removes line breaks and other non-printing characters from pasted data. |
Common mistakes
- TRIM doesn't remove non-breaking spaces (character 160) from web pages. Use
=TRIM(SUBSTITUTE(A2,CHAR(160)," ")). - The cleaned text is in a new column. To replace the original, copy the results and Paste Values over it.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Remove extra spaces from text
B2, remove the extra spaces from the imported name and fill down to B6.Questions
How do I remove all spaces, not just extra ones?
Use SUBSTITUTE: =SUBSTITUTE(A2," ","").
Why does my lookup still fail after TRIM?
Check for non-breaking spaces or for a number stored as text in one of the two lists.
Checked by running on 2026-10-29: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.