TRIM Function in Excel, Google Sheets, Airtable & Notion
TRIM removes spaces from the start and end of text and shrinks any run of spaces inside it to a single space. “ Quarterly report ” becomes “Quarterly report”.
Syntax in each app
| App | Support | Syntax & notes |
|---|---|---|
| Excel | ✔ Built in | TRIM(text) |
| Google Sheets | ✔ Built in | TRIM(text) |
| Airtable | ✔ Built in | TRIM(string)Airtable's TRIM only removes spaces at the start and end. To also shrink double spaces inside the text, as Excel does, use TRIM(REGEX_REPLACE(text, " +", " ")). |
| Notion | ≈ Workaround | replaceAll(replaceAll(text, " +", " "), "^ | $", "")No reliable trim function. Use replaceAll() with a regular expression: first shrink runs of spaces, then remove the one left at either end. |
| Excel | =TRIM(" Quarterly report ") | open excel.new ↗ |
|---|---|---|
| Google Sheets | =TRIM(" Quarterly report ") | open sheets.new ↗ |
| Airtable | TRIM(REGEX_REPLACE(" Quarterly report ", " +", " ")) | |
| Notion workaround | replaceAll(replaceAll(" Quarterly report ", " +", " "), "^ | $", "") |
Excel & Sheets use cell ranges. Paste this sample data into cell A1 of a blank sheet, then paste the formula into any empty cell.
Arguments
| Argument | What it means |
|---|---|
text | The text to clean. |
Examples
| Formula | Result | Why | Copy |
|---|---|---|---|
=TRIM(" Quarterly report ") | Quarterly report | Leading, trailing and double spaces removed. | |
=TRIM(SUBSTITUTE(A2, CHAR(160), " ")) | Cleaned web text | Turn non-breaking spaces into normal spaces first. | |
=TRIM(CLEAN(A2)) | No spaces or line breaks | CLEAN removes line breaks and other control characters. | |
=LEN(A2)<>LEN(TRIM(A2)) | TRUE if messy | Flag cells with stray spaces. |
Examples use Excel / Google Sheets syntax unless noted.
How TRIM works
Stray spaces are a common reason lookups fail: “Apple ” with a trailing space does not match “Apple”, so VLOOKUP and MATCH return #N/A and COUNTIF misses rows. Clean imported or pasted data with TRIM in a helper column, then paste the results back as values.
TRIM only removes the normal space character (code 32). Text copied from web pages often contains non-breaking spaces (code 160), which TRIM leaves alone. Convert them first with =TRIM(SUBSTITUTE(A2, CHAR(160), " ")). Line breaks and tabs need CLEAN() or a SUBSTITUTE of CHAR(10).
The apps disagree on what “trim” means. Excel and Google Sheets also collapse double spaces inside the text. Airtable's TRIM only strips the ends, so the copy button adds a REGEX_REPLACE to match Excel. Notion has no trim function to rely on; two replaceAll() calls with regular expressions do the same job.
Frequently Asked Questions
- Why doesn't TRIM remove all the spaces?
- The remaining characters are probably non-breaking spaces (CHAR(160)) from web text. Use
=TRIM(SUBSTITUTE(A2, CHAR(160), " ")). - How do I remove every space, not just extra ones?
- Use SUBSTITUTE:
=SUBSTITUTE(A2, " ", "").