# TRIM function in Excel

> TRIM removes spaces from the start and end of text and shrinks runs of spaces between words to one.

Source: https://spreadsheetpractice.com/functions/trim · Updated October 28, 2026 · Formulas and results on this page were run by the Spreadsheet Practice formula engine on November 20, 2026

## Quick answer

- **What it does:** TRIM removes spaces from the start and end of text and shrinks runs of spaces between words to one.
- **Syntax:** `=TRIM(text)`
- **Most common use:** `=TRIM(A2)` returns Maya Chen (Leading spaces removed)
- **Available in:** Every current version
- **Category:** [Text functions](https://spreadsheetpractice.com/functions/category/text)
- **Returns:** Text with single spaces between words and none at either end.
- **Google Sheets:** Works the same in Google Sheets.

## What it does

TRIM removes spaces from the start and end of text and shrinks runs of spaces between words to one. It's the first fix to try when lookups return #N/A or duplicates don't look like duplicates, because imported data is full of invisible spaces.

## Syntax

`=TRIM(text)`

| Argument | Required? | What it is |
|---|---|---|
| `text` | Required | The text or cell to clean. |

## Examples

Each result was calculated by running the formula on the sample sheet.

| Cell | Formula | Result | What it shows |
|---|---|---|---|
| D2 | `=TRIM(A2)` | Maya Chen | Leading spaces removed |
| D3 | `=LEN(A3)-LEN(TRIM(A3))` | 2 | How many extra spaces the cell had |
| D4 | `=TRIM(C4)` | Ships Monday | Runs of spaces between words become one |

### The sample sheet

Every formula above runs on this data:

|  | A | B | C | D |
|---|---|---|---|---|
| 1 | Customer (imported) | Phone | Note | Result |
| 2 | Maya Chen | 612-555-0148 | Call after 3pm | Maya Chen |
| 3 | Raj  Patel | 763-555-0193 | VIP | 2 |
| 4 | Lee Wong | 952-555-0107 | Ships   Monday | Ships Monday |

## Common mistakes

| What you see | Why, and how to fix it |
|---|---|
| Spaces copied from websites survive | Web pages and PDFs often use the nonbreaking space (character 160), which TRIM doesn't remove. Convert it first: =TRIM(SUBSTITUTE(A2,CHAR(160)," ")). |
| Lookups still return #N/A | The lookup table may have spaces too. Clean that column as well, or trim inside the lookup: =XLOOKUP(TRIM(A2),TRIM(D2:D9),E2:E9). |
| Numbers stay text | TRIM returns text, so a trimmed " 42 " is "42", not 42. Add 0 or wrap it in VALUE to get a number back. |

## Tips

- Highlight cells with extra spaces using a conditional formatting rule such as =LEN(A2)<>LEN(TRIM(A2)).

## Related functions

- [CLEAN](https://spreadsheetpractice.com/functions/clean): CLEAN removes non-printing characters, such as line breaks and tabs, from text.
- [SUBSTITUTE](https://spreadsheetpractice.com/functions/substitute): SUBSTITUTE replaces specific text with new text everywhere it appears, or only at the occurrence you choose.
- [LEN](https://spreadsheetpractice.com/functions/len): LEN counts the characters in a text string, including spaces and punctuation.

## Questions

### Why isn't TRIM removing spaces in Excel?

The spaces are probably nonbreaking spaces (character 160) from a web page or PDF. TRIM only removes regular spaces. Use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).

### Does TRIM remove the spaces between words?

Only the extras. Two or more spaces between words become one; a single space stays.

## Practice

A graded TRIM exercise ("Clean names") is on [the TRIM page](https://spreadsheetpractice.com/functions/trim). It is checked instantly, then re-checked on changed data.

Lessons that use TRIM:

- [Lesson 20: Cleaning messy data](https://spreadsheetpractice.com/learn/cleaning-messy-data) (Pro)
- [Lesson 22: Splitting and counting list cells](https://spreadsheetpractice.com/learn/textsplit-count-clean-lists) (Pro)

---

Spreadsheet Practice (https://spreadsheetpractice.com) teaches spreadsheet formulas by practice: every exercise is graded in a live grid and re-checked on changed data.
