Remove Extra Spaces From Text
TRIM removes spaces from the start and end of a cell and reduces repeated spaces between words to one. Text copied from web pages often contains non-breaking spaces that TRIM misses, which need SUBSTITUTE as well. Describe your data below and get the cleaning formula.
Free, no sign-up required · 5 free generations a day
Last updated
Describe your task, get the formula
Type what you need in plain English, or pick an example below. You get the formula, a step-by-step explanation, and a worked example.
Formulas for removing spaces
=TRIM(A2)
=TRIM(SUBSTITUTE(A2,CHAR(160)," "))
=SUBSTITUTE(A2," ","")TRIM handles ordinary spaces. CHAR(160) is the non-breaking space used on web pages; SUBSTITUTE swaps it for a normal space so TRIM can remove it. The last formula deletes every space, which is useful for phone numbers and codes.
Examples
Clean web or PDF text completely
=TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," ")))SUBSTITUTE converts non-breaking spaces, CLEAN deletes line breaks and other non-printing characters, and TRIM tidies the remaining spaces.
Remove every space
=SUBSTITUTE(A2," ","")Replaces each space with nothing, turning 555 010 9999 into 5550109999. The result is text; wrap it in VALUE if you need a number.
Clean a number stored as text with spaces
=VALUE(SUBSTITUTE(TRIM(A2)," ",""))Strips the spaces and converts what is left into a real number that can be summed and sorted.
Common mistakes and how to fix them
TRIM does not remove the spaces
They are non-breaking spaces. Check with =CODE(RIGHT(A2,1)): a result of 160 confirms it. Use the SUBSTITUTE with CHAR(160) formula.
Lookups still fail after cleaning
The cleaned values are in a new column while the lookup still points at the old one. Copy the cleaned column and use Paste Special, Values over the original.
Dates or numbers turn into text
TRIM always returns text. Wrap the result in VALUE for numbers or DATEVALUE for dates.
Frequently asked questions
Can I clean a whole column with one formula?
In Excel 365 and Google Sheets, yes: =TRIM(A2:A100) in Excel spills the cleaned list, and =ARRAYFORMULA(TRIM(A2:A100)) does the same in Google Sheets.
Does Google Sheets have a built-in tool for this?
Yes. Select the cells and choose Data, Data cleanup, Trim whitespace. It edits the cells in place, without a formula.
How do I remove only leading spaces and keep the rest?
Use =MID(A2,FIND(LEFT(TRIM(A2),1),A2),LEN(A2)). It finds the first real character and returns everything from there on.
Don't want to write it by hand?
Describe what you need in plain English and get a ready-to-use formula in seconds.
Try the formula generator