How to Use the TRIM Function in Excel
TRIM removes extra spaces from text in Excel. Use it to clean imports, vendor names, lookup keys, and pasted data before formulas break.
Reviewed by Griddy
Updated for current Excel and Google Sheets workflows, with examples chosen to map back to real spreadsheet tasks rather than abstract formula syntax.
TRIM removes extra spaces from text. It is a small function, but it fixes a lot of spreadsheet problems caused by exports, pasted data, and inconsistent typing.
Use it when vendor names do not match, lookup keys fail for no obvious reason, or category labels look the same but behave like different values.
The syntax
=TRIM(text)- text - the cell or text value you want to clean
TRIM removes leading spaces, trailing spaces, and repeated spaces between words. It leaves one normal space between words.
Example: clean vendor names before a lookup
Suppose column A has vendor names from a card export. Some rows have extra spaces:
Acme Supplies
Acme Supplies
Acme Supplies
Acme Supplies
Those can look nearly identical in the sheet, but Excel treats them as different text values.
Step 1. Add a clean helper column
In B2, enter:
=TRIM(A2)Step 2. Fill the formula down
Copy the formula down the vendor list. Column B now has normalized names.
Step 3. Use the clean column in formulas
Use the cleaned vendor name for lookups, pivots, SUMIF reports, and category mapping. That keeps one vendor from turning into three separate rows in your summary.
✦ TIP
TRIM with non-breaking spaces
TRIM does not remove every kind of space. Data copied from websites, PDFs, or some accounting exports can include non-breaking spaces, which look like ordinary spaces but are different characters.
If TRIM does not fix the issue, use SUBSTITUTE first:
=TRIM(SUBSTITUTE(A2, CHAR(160), " "))That replaces non-breaking spaces with normal spaces, then TRIM cleans the result.
Common issues
| Issue | Cause | Fix |
|---|---|---|
| Lookup still fails | Text contains non-breaking spaces | Use SUBSTITUTE(A2, CHAR(160), " ") before TRIM |
| Numbers become text | The source value is stored as text | Clean the text, then convert the result if needed |
| Spaces inside codes disappear? | TRIM keeps single spaces between words | Use SUBSTITUTE only when you intentionally want to remove all spaces |
| Pivot table has duplicate labels | Labels differ by hidden spaces | Build the pivot from the TRIM helper column |
When TRIM is most useful
TRIM is worth using before anything that depends on exact text:
- vendor cleanup
- customer name matching
- category mapping
- invoice ID cleanup
- VLOOKUP or XLOOKUP keys
- pivot table row labels
It is also useful before combining text from several fields. Clean each source field first so the final label does not carry strange spacing.
The Griddy way
Text cleanup gets boring fast when you have several columns with hidden spaces and inconsistent labels.
"Clean the vendor and category columns, remove extra spaces, then summarize expenses by category"
Griddy can add the helper formulas, clean the imported data, and build the summary without making you inspect each row by hand.
Skip the manual work
Describe it. Griddy does it.
Instead of writing this formula yourself, just tell Griddy what you need in plain English. Works in Excel and Google Sheets.