Skip to content
getgriddy.ai/blog/how-to-use-trim-function-in-excel
Excel

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.

·5 min read

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

fx
=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:

fx
=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

When you clean imported text, keep the original column until you have checked the results. It gives you a quick way to audit what changed.

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:

fx
=TRIM(SUBSTITUTE(A2, CHAR(160), " "))

That replaces non-breaking spaces with normal spaces, then TRIM cleans the result.

Common issues

IssueCauseFix
Lookup still failsText contains non-breaking spacesUse SUBSTITUTE(A2, CHAR(160), " ") before TRIM
Numbers become textThe source value is stored as textClean the text, then convert the result if needed
Spaces inside codes disappear?TRIM keeps single spaces between wordsUse SUBSTITUTE only when you intentionally want to remove all spaces
Pivot table has duplicate labelsLabels differ by hidden spacesBuild 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.