Text formula page
Remove Extra Spaces Formula
Use TRIM when imported names, categories, or IDs contain accidental extra spaces.
Remove extra spaces from spreadsheet text.
If A2 is two-space padded text, the formula returns cleaned spacing.
Copy formulas
=TRIM(A2)=TRIM(A2)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 Text | Example Result |
|---|---|
| Maya Chen | Maya |
| SKU-1001-East | SKU |
| https://www.example.com/pricing | example.com |
| Acme North | Acme North |
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 piece | Role in the formula |
|---|---|
| A2 | The source text containing spacing to clean. |
| TRIM | The function that removes leading and trailing ordinary spaces. |
| repeated spaces | Ordinary internal spaces are reduced to one space between words. |
Verified examples
=TRIM(A2)Excel: Enter two leading spaces, Acme, three internal spaces, North, and two trailing spaces in A2. Returns: Acme North
=TRIM(SUBSTITUTE(A2,CHAR(160)," "))Google Sheets: Enter Acme, a CHAR(160) nonbreaking space, and North in A2. Returns: Acme North
=TRIM(A2)Excel: Enter SKU-1001-East in A2. Returns: SKU-1001-East
Common errors and fixes
| Issue | Likely cause | Fix |
|---|---|---|
| A visible gap remains after TRIM | The source contains a nonbreaking space such as CHAR(160). | Replace CHAR(160) with an ordinary space before applying TRIM. |
| Line breaks remain | TRIM handles spaces, not all line-break characters. | Use a line-break cleanup formula before or around TRIM. |
| Meaningful spacing is changed | TRIM 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
| Alternative | When to use it |
|---|---|
| Remove Line Breaks Formula | Use when imported cells contain carriage returns or line feeds. |
| CSV Column Cleaner | Use when a whole imported CSV column needs deterministic cleanup. |
Related formulas
Official references
- TRIM function from Microsoft
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.