Skip to main content

Text formula page

Remove Extra Spaces Formula

Use TRIM when imported names, categories, or IDs contain accidental extra spaces.

Best for

Remove extra spaces from spreadsheet text.

What it returns

If A2 is two-space padded text, the formula returns cleaned spacing.

Copy formulas

Excel formula
=TRIM(A2)
Google Sheets formula
=TRIM(A2)
Excel / Google Sheets difference

TRIM removes leading and trailing ordinary spaces and collapses repeated ordinary internal spaces in both Excel and Google Sheets; it does not remove nonbreaking spaces by itself.

Example data

Raw TextExample Result
Maya ChenMaya
SKU-1001-EastSKU
https://www.example.com/pricingexample.com
Acme North Acme North
What it returns

If A2 is two-space padded text, the formula returns cleaned spacing.

How the formula works

  • TRIM removes leading and trailing spaces.
  • It also reduces repeated regular spaces inside text.
  • Use SUBSTITUTE for nonbreaking spaces.
Syntax pieceRole in the formula
A2The source text containing spacing to clean.
TRIMThe function that removes leading and trailing ordinary spaces.
repeated spacesOrdinary internal spaces are reduced to one space between words.

Verified examples

Collapse ordinary spaces
=TRIM(A2)

Excel: Enter two leading spaces, Acme, three internal spaces, North, and two trailing spaces in A2. Returns: Acme North

Replace nonbreaking space
=TRIM(SUBSTITUTE(A2,CHAR(160)," "))

Google Sheets: Enter Acme, a CHAR(160) nonbreaking space, and North in A2. Returns: Acme North

Preserve single SKU spacing
=TRIM(A2)

Excel: Enter SKU-1001-East in A2. Returns: SKU-1001-East

Common errors and fixes

IssueLikely causeFix
A visible gap remains after TRIMThe source contains a nonbreaking space such as CHAR(160).Replace CHAR(160) with an ordinary space before applying TRIM.
Line breaks remainTRIM handles spaces, not all line-break characters.Use a line-break cleanup formula before or around TRIM.
Meaningful spacing is changedTRIM collapses repeated ordinary spaces inside the text.Use a targeted replacement when repeated spaces carry meaning in the source.

When not to use this formula

  • Do not use TRIM when repeated internal spaces are meaningful formatting that must be preserved.

Alternatives

AlternativeWhen to use it
Remove Line Breaks FormulaUse when imported cells contain carriage returns or line feeds.
CSV Column CleanerUse when a whole imported CSV column needs deterministic cleanup.

Related formulas

Official references

FAQ

Does TRIM handle CHAR(160)?

No. Replace CHAR(160) with an ordinary space first, then apply TRIM.

What happens to repeated internal spaces?

TRIM reduces repeated ordinary internal spaces to one space.