TRIM

Remove extra spaces from text with Excel's TRIM function, leaving single spaces between words.

|
Excel All versions
|
Google Sheets Supported

Spreadsheet editor

Syntax

=TRIM(text) Returns: Text

Arguments

Argument Required Description
text Yes The text or cell reference containing the text you want to clean up.

About

TRIM removes extra spaces from text and returns a clean version. It strips the spaces before and after the text, and reduces any run of spaces between words down to a single space. You give it one piece of text or a cell reference, and it hands back the tidied string.

Use TRIM whenever you paste or import data and the spacing looks off. Names copied from a website, codes from another system, or values typed by hand often carry hidden spaces that break lookups, sorting, and joins. Cleaning the text first can mean VLOOKUP and XLOOKUP actually find their matches.

Keep in mind TRIM only handles the standard space character. It will not touch non-printable characters or the non-breaking spaces that often come from web pages. For those, pair it with CLEAN, or use SUBSTITUTE when you need to remove every space, including the ones between words.

Examples

Count the hidden spaces in your data

Pair TRIM with LEN to audit messy names. The last column shows exactly how many stray spaces each entry was hiding. Edit a name and watch the count update.

Spreadsheet editor

Remove every space, not just the extras

Watch what happens when you expect TRIM to delete all spaces. It keeps a single space between words, so "New York" stays "New York". Compare it with SUBSTITUTE to strip every space.

Spreadsheet editor

Watch out for

Non-breaking spaces stay put

Text copied from websites often contains non-breaking spaces (character 160). TRIM only removes the standard space (character 32), so the value can still look untidy and lookups still fail.

Convert the non-breaking spaces first with SUBSTITUTE, for example =TRIM(SUBSTITUTE(A2,CHAR(160)," ")), or run CLEAN alongside TRIM.

Expecting it to remove all spaces

TRIM keeps single spaces between words, so it will not turn "New York" into "NewYork". People sometimes reach for it to strip every space.

To remove every space, use SUBSTITUTE instead, such as =SUBSTITUTE(A2," ","").

The original cell still has spaces

TRIM returns a cleaned copy in a new cell. The source cell keeps its extra spaces, which can confuse later steps that still point at the original.

Copy the TRIM results, then paste them back over the original data as values once you are happy with the output.

Tips & notes

TRIM also accepts numbers, but it converts them to text in the process, so wrap the result in VALUE if you need to do math with it afterwards. To check your work, compare LEN on the original and trimmed text to see how many spaces were removed.

Common questions

Does TRIM remove spaces between words?

Not all spaces. It keeps a single space between words. TRIM only removes the leading and trailing spaces and collapses any repeated spaces in the middle down to one.

Why does TRIM leave some spaces behind?

Those are likely non-breaking spaces (character 160), which are common in text copied from web pages. TRIM only handles the standard space, so swap them out with SUBSTITUTE and CHAR(160) first.

What is the difference between TRIM and CLEAN?

TRIM removes extra spaces, while CLEAN removes non-printable characters such as line breaks and tabs. They are often used together as =TRIM(CLEAN(A2)) to fully tidy imported text.

Can TRIM change the original cell?

No, it returns a new cleaned value and leaves the source cell as it is. To replace the original, copy the result and paste it back as values.