TRIM Function in Excel — Kill Invisible Spaces That Break Your Formulas (2026) | Sheets & Cells
Text · Cleanup Trio

TRIM Function in Excel

Removes leading, trailing, and duplicate internal spaces from text. The unglamorous hero that fixes VLOOKUP failures, silent duplicates, and every "why isn't this matching?" bug caused by phantom whitespace in imported data.

Universal Support
TRIM has existed in Excel since Excel 1.0 (1985). Works identically in Excel 2003, 2007, 2010, 2013, 2016, 2019, 2021, Microsoft 365, Excel Online, Excel Mobile, Google Sheets, and LibreOffice Calc. No compatibility caveats.

The Invisible Space Problem

Your VLOOKUP returns #N/A. The value is right there. What's actually happening?

Real scenario: You import a customer list from a CRM. You try to look up "Emma Thompson" — it fails. You copy the name from the source cell, paste it into your formula — still fails. The two strings look identical to you but Excel disagrees, because one of them has a trailing space you can't see.
Without TRIM
=VLOOKUP("Emma Thompson", A:B, 2, 0)

Cell contains "Emma Thompson " (trailing space). VLOOKUP sees them as different strings.

#N/A
With TRIM
=VLOOKUP("Emma Thompson", TRIM(A:B), 2, 0)

TRIM strips the invisible space before the match. Formula works instantly.

$4,850

Quick Answer

TRIM removes all leading and trailing spaces from a text string, and reduces any runs of multiple spaces between words to a single space.

=TRIM(text)

Example: =TRIM(" Emma Thompson ") returns "Emma Thompson". Notice: internal single spaces are preserved — TRIM never merges words.

📊 Text Cleanup Trio Practice Workbook

All 5 TRIM examples plus LEN and SUBSTITUTE patterns, on 20 rows of realistic messy CRM data.

↓ Download .xlsx (Free)
Filetext-cleanup-trio-2026.xlsx
Size~22 KB
Sheets6 tabs
CoversTRIM · LEN · SUBSTITUTE
1985
Introduced
1
Argument
100%
Compat
80+
Templates Use It

Syntax

TRIM takes exactly one argument — the text you want to clean.

ArgumentTypeDescription
text Required The text string, or a reference to a cell containing text, from which spaces should be removed. Accepts a literal string, a cell reference, or another formula's text output.

What TRIM removes: ASCII space characters (character code 32) — from the start, from the end, and any duplicates in the middle. What TRIM ignores: non-breaking spaces (CHAR 160, common in web/Word copy-paste), tabs, line breaks, and other non-printing characters. Those need CLEAN or SUBSTITUTE.

5 Worked Examples

Example 01

Basic — remove leading and trailing spaces

The most common use. Copy-paste from a PDF or CRM export typically leaves a space at the start, the end, or both.

CellRaw InputFormulaResult
A2" Emma Thompson "=TRIM(A2)"Emma Thompson"
A3"David Kim "=TRIM(A3)"David Kim"
A4" Sofia Rodriguez"=TRIM(A4)"Sofia Rodriguez"

TRIM handles leading, trailing, or both — same formula, no configuration.

Example 02

Collapse multiple internal spaces

When someone types "David   Kim" (three spaces) instead of one, TRIM fixes it silently.

=TRIM("David Kim")

Returns: "David Kim" — three internal spaces collapsed to one. TRIM only ever leaves single spaces between words. It never joins them into one word.

Example 03

Fix a VLOOKUP that's returning #N/A

The most valuable use of TRIM. When lookup keys don't match despite looking identical, phantom spaces are almost always the reason.

AttemptFormulaResult
Broken=VLOOKUP("Emma Thompson", A2:B100, 2, 0)#N/A
Fixed (lookup)=VLOOKUP(TRIM("Emma Thompson"), A2:B100, 2, 0)#N/A (still fails if source has spaces)
Fixed properly=VLOOKUP("Emma Thompson", TRIM(A2:B100), 2, 0)$4,850

The permanent fix: run TRIM once over the source column (as a helper column), then look up against the clean values. Alternatively, wrap the lookup range in TRIM as an array formula (Excel 365).

Example 04

The CHAR(160) trap — non-breaking spaces TRIM can't touch

Text copy-pasted from Word, web pages, or PDF often contains character code 160 — a non-breaking space that looks identical to a normal space but isn't. TRIM ignores it. Nightmare bug.

FormulaExplanationLength Result
=LEN(TRIM(CHAR(160)&"Emma"&CHAR(160)))TRIM alone. Fails silently.6 (still has 2 phantoms)
=LEN(TRIM(SUBSTITUTE(CHAR(160)&"Emma"&CHAR(160), CHAR(160), " ")))SUBSTITUTE converts CHAR(160)→space, then TRIM works.4 (just "Emma")

This is the single biggest reason "why isn't TRIM working?" — the answer is almost always CHAR(160). Standard cleanup: =TRIM(SUBSTITUTE(A2, CHAR(160), " ")).

Example 05

TRIM + CLEAN — the maximum-cleanup combo

CLEAN removes all non-printing characters (line breaks, tabs, control codes 0–31). TRIM handles the spaces. Nested, they handle nearly anything imported.

=TRIM(CLEAN(A2))

Use this any time your data source is unpredictable — email dumps, PDF extracts, HTML paste, CSV imports of dubious quality. It's the "kitchen sink" cleanup. Add SUBSTITUTE for CHAR(160) to make it truly bulletproof: =TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " "))).

Interactive Playground

Dirty Inputs
A2 → " Emma Thompson "
A3 → "David Kim"
A4 → " MICHAEL Chen"
A5 → "sofia rodriguez "
A6 → " Aisha Patel "
=TRIM(A2:A6)
=TRIM(A2)
"Emma Thompson"
"David Kim"
"MICHAEL Chen"
"sofia rodriguez"
"Aisha Patel"

Note: TRIM only fixes spaces. Case (MICHAEL, sofia) needs PROPER or LOWER separately.

The Text Cleanup Trio

Three functions that work together to turn messy imports into production-clean data.

TRIM vs CLEAN — What Each One Actually Removes

Different jobs, often used together. Here's the exact split.

Character typeTRIM removes it?CLEAN removes it?
Leading/trailing regular spaces (CHAR 32)✓ YES✗ NO
Duplicate internal spaces✓ YES✗ NO
Non-breaking spaces (CHAR 160)✗ NO✗ NO
Line breaks (CHAR 10, 13)✗ NO✓ YES
Tabs (CHAR 9)✗ NO✓ YES
Non-printing control codes (CHAR 0–31)✗ NO✓ YES

For CHAR(160) — the most common "why isn't TRIM working?" bug — you need SUBSTITUTE. The full defensive cleanup: =TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " ")))

The Single-Space Rule

TRIM never joins words together — that's the guarantee.

" Emma Thompson " "Emma Thompson"
"David Kim" "David Kim"
"one two three" "one two three"

If you actually want to remove internal spaces entirely (e.g. "New York" → "NewYork"), TRIM won't do it. Use SUBSTITUTE: =SUBSTITUTE(A2, " ", "") removes every space.

Common Errors

SymptomCauseFix
TRIM appears to do nothing The "spaces" are actually CHAR(160) non-breaking spaces from web/Word paste. TRIM only removes CHAR(32). Wrap with SUBSTITUTE: =TRIM(SUBSTITUTE(A2, CHAR(160), " ")).
VLOOKUP still fails TRIM only cleans the value you look up, not the source range. The source still has ghost spaces. Add a helper column with =TRIM(A2) for every source row. Look up against the helper column, not the raw one.
#VALUE! Argument is an error value (e.g. =TRIM(#N/A)). Wrap with IFERROR: =IFERROR(TRIM(A2), "").
Numbers become text TRIM always returns text. If you TRIM a number, the result won't sum correctly. Convert back with VALUE: =VALUE(TRIM(A2)). Or use a formula that accepts text-numbers, like --(TRIM(A2)).
Line breaks still present TRIM doesn't touch line breaks (CHAR 10/13). Only ASCII spaces. Nest with CLEAN: =TRIM(CLEAN(A2)). CLEAN handles all non-printing characters.

📊 Practice on Real Messy Data

20 rows of realistic CRM export junk — spaces, CHAR(160), mixed case. All 5 TRIM examples plus the full cleanup pipeline.

↓ Get Workbook

Related Functions

Compatibility

PlatformSupportedVersionNotes
Excel for Windows1.0+ (1985)All versions
Excel for Mac1.0+All versions
Microsoft 365CurrentFull support
Excel OnlineCurrentFull support
Excel Mobile (iOS/Android)CurrentFull support
Google SheetsAllIdentical behavior
LibreOffice CalcAllIdentical behavior

How to Use TRIM — Step by Step

  1. Click an empty cell next to the messy text you want to clean. If your dirty data is in column A, use column B for the TRIM helper.
  2. Type =TRIM( — Excel auto-suggests as soon as you type "TR".
  3. Click the messy cell (e.g. A2) or type its reference. Close the parenthesis with ) and press Enter.
  4. Copy the formula down. Grab the fill handle (small square at the bottom-right of the cell) and drag down the length of your data. Or double-click it — Excel auto-fills to match column A's height.
  5. If TRIM appears to do nothing, the culprit is almost always CHAR(160). Change your formula to =TRIM(SUBSTITUTE(A2, CHAR(160), " ")). This is the industry-standard cleanup.
  6. To lock in the cleaned values, select the TRIM column → Copy → Paste Special → Values. Now delete column A and rename the TRIM column. The clean data replaces the mess.

Explore More Functions

📊 One More Time — Grab the Workbook

Every TRIM pattern, LEN validation, and SUBSTITUTE trick — one file, six sheets, free forever.

↓ Download Free

Frequently Asked Questions

Why does TRIM seem to do nothing on some cells?

The "spaces" you see aren't regular spaces — they're CHAR(160) non-breaking spaces, which TRIM ignores. This is the single most common TRIM complaint, and it happens whenever you paste from Word, a web page, a PDF, or copy from certain database exports.

The fix: =TRIM(SUBSTITUTE(A2, CHAR(160), " ")). SUBSTITUTE converts CHAR(160) to a regular space, then TRIM handles the rest. Bookmark this formula — you'll use it constantly.

Does TRIM remove spaces between words?

No — TRIM never joins words together. It removes leading and trailing spaces completely, but between words it reduces any run of multiple spaces to exactly one single space. That's the guarantee.

If you want to remove all spaces entirely (e.g. "New York" → "NewYork"), use SUBSTITUTE instead: =SUBSTITUTE(A2, " ", "").

Will TRIM fix my VLOOKUP that returns #N/A?

Only if you TRIM the source range, not just the lookup value. The pattern =VLOOKUP(TRIM("Emma"), A:B, 2, 0) still fails if column A itself has trailing spaces.

The permanent fix: add a helper column (e.g. column C) with =TRIM(A2) for every row. Point your VLOOKUP at column C instead of column A. Alternatively, in Excel 365 you can use =XLOOKUP("Emma", TRIM(A:A), B:B) as an array formula, but the helper column is faster.

What's the difference between TRIM and CLEAN?

TRIM removes only ASCII space characters (CHAR 32) — from the start, end, and any duplicates in the middle. CLEAN removes non-printing characters (CHAR 0–31) like line breaks, tabs, and control codes, but leaves spaces alone.

They complement each other. For maximum cleanup, nest them: =TRIM(CLEAN(A2)). Neither one handles CHAR(160) non-breaking spaces — you need SUBSTITUTE for that.

Can TRIM handle numbers?

Yes — TRIM accepts any value and converts it to text before processing. But the result is always text, even if the input was a number. That means TRIM(1234) returns "1234" as text, which won't sum correctly.

To convert back to a number, wrap with VALUE: =VALUE(TRIM(A2)). Or use the double-negative trick: =--TRIM(A2), which forces numeric conversion.

How do I TRIM an entire column at once?

Two approaches. Traditional: add a helper column with =TRIM(A2), drag down the entire column, then Copy → Paste Special → Values back over column A to replace the messy version.

Modern (Excel 365 / 2021): use a spill formula in a single cell: =TRIM(A2:A100). It expands automatically to fill the range. To replace the source column, copy the spill result and paste values over A2:A100.

Does TRIM work in Google Sheets and LibreOffice?

Yes, identically. TRIM is one of the most universal spreadsheet functions — every mainstream tool implements it the same way. Formulas that use TRIM port between Excel, Google Sheets, LibreOffice Calc, and OnlyOffice without any modification.

Can TRIM cause data loss?

No — TRIM only removes spaces (specifically CHAR 32). It never removes letters, numbers, punctuation, or any other characters. The worst it can do is fail to clean CHAR(160), which is a no-op, not data loss.

However, if you use Paste Special Values to replace your source column, that's when you lose the original spaces permanently. Test on a copy first if the raw data has any semantic meaning (rare, but possible with tab-delimited log data).

Is there a way to TRIM only leading OR only trailing spaces?

Not directly — TRIM always does both plus internal collapse. For leading-only, use =IFERROR(RIGHT(A2, LEN(A2)-FIND(LEFT(TRIM(A2),1), A2)+1), A2). For trailing-only, one clean approach: =TRIM(A2)&IF(RIGHT(A2,1)=" ","","")) — but honestly, both approaches are usually overkill.

If you really need surgical control, use Power Query's "Trim" transformation, which offers left-only, right-only, or both options.

How do I count how many spaces TRIM removed?

Subtract the lengths: =LEN(A2) - LEN(TRIM(A2)). Returns the exact number of characters removed. Great for a data-quality dashboard column: "how much junk did TRIM strip from this row?"

If the answer is 0 for a row that clearly has visible spaces, that's your signal to switch to the SUBSTITUTE + CHAR(160) formula.

Can I use TRIM inside conditional formatting?

Yes. Common pattern: flag cells that need cleaning with =A2<>TRIM(A2). Any cell where the value differs from its trimmed version gets highlighted — a fast visual audit of which rows have phantom spaces before you fix them.

What's the fastest full-cleanup formula?

For text-only cleanup: =TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " "))). This handles regular spaces, non-breaking spaces, line breaks, tabs, and control characters in one pass.

Add PROPER for name-case normalization: =PROPER(TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " ")))). This is the "kitchen sink" formula for customer-name columns after any CRM export.

Kill Data-Cleanup Bugs Once and for All

Excel Wizard writes the exact TRIM + CLEAN + SUBSTITUTE pipeline your messy data needs — from a plain-English prompt. Fixes VLOOKUP failures, CHAR(160) traps, and case-normalization in one go, right inside Excel.

Get Excel Wizard Add-in →