# TRIM formula generator

> Describe what you need and get a TRIM formula for Excel and Google Sheets, run on real data before you copy it. Plus 8 tested TRIM examples.

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

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

Describe the task at [TRIM formula generator](https://spreadsheetpractice.com/tools/formula-generator/trim) and get a TRIM formula for Excel and Google Sheets, tested on real data.

## Tested TRIM examples

### Remove extra spaces from text

`=TRIM(A2)`

Excel. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/remove-extra-spaces)

### Change text to uppercase

`=UPPER(A2)`

Excel. Result on the sample sheet: 6 rows (B2:B7). [See it and try it](https://spreadsheetpractice.com/formulas/change-text-to-uppercase)

### Change text to lowercase

`=LOWER(A2)`

Excel. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/change-text-to-lowercase)

### Fix dates stored as text

`=DATEVALUE(A2)`

Excel. Result on the sample sheet: 6 rows (B2:B7). [See it and try it](https://spreadsheetpractice.com/formulas/fix-dates-stored-as-text)

### Remove non-printing characters

`=TRIM(CLEAN(A2))`

Excel. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/remove-non-printing-characters)

### Compare two columns ignoring extra spaces and case

`=TRIM(A2)=TRIM(B2)`

Excel. Result on the sample sheet: 6 rows (C2:C7). [See it and try it](https://spreadsheetpractice.com/formulas/compare-two-columns-ignoring-spaces)

### Why COUNTIF returns 0 when the value is there

`=SUMPRODUCT(--(TRIM(A2:A10)=E1))`

Excel. Result on the sample sheet: 3. [See it and try it](https://spreadsheetpractice.com/formulas/countif-returns-zero)

### Remove special characters from text

`=TRIM(REGEXREPLACE(A2,"[^A-Za-z0-9 ]",""))`

Google Sheets. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/remove-special-characters)

## Questions

### What does the TRIM formula generator do?

You describe the task in plain English, and it writes the formula, using TRIM where that's the right tool, for your table or a sample one. The formula is run in our engine in Excel and Google Sheets mode before you see it, so you get its result, not just a guess.

### What does TRIM do?

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

### Can I learn to write TRIM formulas myself?

Yes. Each example below opens a page where you try the formula in a live grid and it's checked as you go, and the TRIM function page has a practice exercise.

---

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