ExcelReady
CourseFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before the interview. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Function guides
  • Blog

Product

  • Certificate

Company

  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Comparisons
  3. TRIM vs CLEAN in Excel

TRIM vs CLEAN in Excel

By ExcelReady Team·Updated October 30, 2026·7 min read

The short answer

TRIM removes extra spaces: every space at the start and end, and all but one space between words. CLEAN removes non-printing characters with codes 0 to 31, such as line breaks and tabs. Use TRIM for spacing problems, CLEAN for hidden characters, and =TRIM(CLEAN(A2)) when imported text has both.

Key takeaways

  • TRIM fixes spaces; CLEAN fixes invisible control characters such as line breaks (CHAR(10)) and tabs (CHAR(9)).
  • =TRIM(CLEAN(A2)) handles both problems in one formula.
  • CLEAN deletes a line break without adding a space, which can glue two words together.
  • Neither removes the non-breaking space, CHAR(160), common in web data. Use SUBSTITUTE for it.
  • Check what you're dealing with first: compare LEN(A2) with LEN(TRIM(A2)).
On this page+
  1. TRIM vs CLEAN at a glance
  2. How TRIM works
  3. How CLEAN works
  4. The same messy text, side by side
  5. How to see what's really in a cell
  6. What neither TRIM nor CLEAN removes
  7. How to clean a whole column
  8. When to use TRIM
  9. When to use CLEAN
  10. Common mistakes with TRIM and CLEAN
  11. Our recommendation
  12. Practise it

TRIM vs CLEAN in Excel comes down to which kind of mess you have. TRIM removes extra spaces: at the start, at the end and the repeats between words. CLEAN removes invisible control characters, such as line breaks and tabs, that sneak in from other systems. Imported data often has both, which is why =TRIM(CLEAN(A2)) is such a common formula. This guide is for anyone whose lookups fail or whose text looks fine but won't match.

TRIM vs CLEAN at a glance#

TRIM deals with the space character; CLEAN deals with characters you can't see at all.

FeatureTRIMCLEAN
Syntax=TRIM(text)=CLEAN(text)
RemovesLeading and trailing spaces, and repeated spaces between wordsNon-printing characters with codes 0–31
Typical culpritsExtra spaces from typing, padding or exportsLine breaks (CHAR(10)), carriage returns (CHAR(13)), tabs (CHAR(9))
KeepsOne space between wordsAll normal text and spaces
Non-breaking space (CHAR(160))Not removedNot removed
Common source of the problemTyped data, fixed-width exportsCopied cells with Alt+Enter breaks, system exports
Excel versionsAllAll

How TRIM works#

TRIM cleans up the normal space character (code 32). It removes every space before the first word and after the last one, and squeezes any run of spaces between words down to a single space:

Excel formula
=TRIM("  Desk   lamp  ")

The result is Desk lamp. TRIM doesn't remove the single space between words, and it doesn't touch any other character. The TRIM function guide has more examples.

How CLEAN works#

CLEAN removes the first 32 characters of the ASCII set, codes 0 to 31. You can't see these characters, but they change how text behaves. The ones you'll meet most often are:

  • CHAR(10), a line break. It's what you type with Alt+Enter on Windows (⌃⌥Return on a Mac) to start a new line inside a cell.
  • CHAR(13), a carriage return, often paired with a line break in files from other systems.
  • CHAR(9), a tab, common in text pasted from other programs.

CLEAN deletes these characters and joins what's left. It does not add a space, which matters when a line break separates two words.

The same messy text, side by side#

Here is one product name exported from a stock system. It has two leading spaces, three spaces in the middle and a line break at the end: " Desk lamp" followed by CHAR(10).

FormulaResultLength
=LEN(A2)14
=TRIM(A2)Desk lamp + line break10
=CLEAN(A2)" Desk lamp"13
=TRIM(CLEAN(A2))Desk lamp9

TRIM alone fixed the spaces but left the line break, so the text is still 10 characters and still won't match "Desk lamp" in a lookup. CLEAN alone removed the line break but left the spaces. Together, they produce the clean 9-character name.

When CLEAN glues words together#

Now an address with a line break between two parts: Unit 4 + CHAR(10) + High Street.

Excel formula
=CLEAN(A3)
=TRIM(SUBSTITUTE(A3,CHAR(10)," "))

CLEAN returns Unit 4High Street, because it simply deletes the break. The second formula swaps the line break for a space first, then TRIM tidies up, giving Unit 4 High Street. Use this version when a line break separates words.

How to see what's really in a cell#

Before you choose a fix, find out what the problem is. Three quick checks:

  1. Compare lengths. If =LEN(A2) is bigger than =LEN(TRIM(A2)), there are extra spaces. If =LEN(CLEAN(A2)) is smaller than =LEN(A2), there are control characters.
  2. Check the last character. =CODE(RIGHT(A2)) shows the code of the last character. 32 is a space, 10 a line break, 9 a tab and 160 a non-breaking space.
  3. Test the match directly. =A2="Desk lamp" returns FALSE if anything invisible is in the way.

What neither TRIM nor CLEAN removes#

The non-breaking space, CHAR(160), is the most common character that survives both functions. It's used on web pages to keep words together, so it often arrives when you copy a table from a browser. It looks exactly like a space. Swap it for a normal space, then TRIM:

Excel formula
=TRIM(SUBSTITUTE(A2,CHAR(160)," "))

For the full clean, combine all three: =TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," "))). Our comparison of SUBSTITUTE vs REPLACE explains how SUBSTITUTE works.

How to clean a whole column#

TRIM and CLEAN don't change the original cell; they return a cleaned copy. To fix a whole column of imported names in column A:

  1. In B2, type =TRIM(CLEAN(A2)) and press Enter.
  2. Select B2 down to the last row and press Ctrl+D (⌘D on a Mac) to fill down. Or double-click the fill handle, the small square at the bottom-right of B2.
  3. Spot-check a few rows with =LEN(A2) and =LEN(B2) to confirm the extra characters are gone.
  4. Copy column B, then paste it over column A as values: Ctrl+Alt+V, then V and Enter on Windows, or ⌃⌘V then Values on a Mac.
  5. Delete the helper column.

Step 4 matters: if you delete column A while B still holds formulas, every cleaned value turns into #REF!. Our comparison of Paste vs Paste Values explains why.

When to use TRIM#

Use TRIM whenever spaces are the problem. It is the right choice when:

  • Lookups return #N/A for values that look identical, because one has a trailing space. Our comparisons of VLOOKUP vs XLOOKUP and VLOOKUP vs INDEX MATCH both list stray spaces as a top cause of failed matches.
  • Names or codes were typed by hand, with double spaces between words.
  • COUNTIF or Remove Duplicates treats "Sales" and "Sales " as two different values.

When to use CLEAN#

Use CLEAN when text contains characters you can't see. It is the right choice when:

  • Cells show text on two lines that should be on one, or a line-break symbol after export.
  • Data came from another system (a CRM, a database export, a PDF) and behaves strangely.
  • LEN is larger than the visible text, even after TRIM.

In practice, =TRIM(CLEAN(A2)) is a safe default for any imported column. Build it in a helper column, check the results, then paste them as values over the original. Our guide to cleaning messy data in Excel walks through a full clean-up with PROPER, UPPER and LOWER too.

Common mistakes with TRIM and CLEAN#

These slips cause most cleaning problems:

  1. Expecting TRIM to remove line breaks. It only handles spaces. Use CLEAN or SUBSTITUTE.
  2. Expecting either to remove CHAR(160). Neither does; use SUBSTITUTE first.
  3. Using CLEAN on text where a line break separates words. The words join up. Replace CHAR(10) with a space instead.
  4. Cleaning the lookup table but not the lookup value (or the other way round). Both sides must match.
  5. Leaving the formulas in place. If you delete the raw column, the cleaned column turns to #REF!. Paste values first.
  6. Thinking TRIM changes numbers. TRIM returns text, so a cleaned "250 " becomes the text "250". Use VALUE if you need a number.

Our recommendation#

Use TRIM for spaces, CLEAN for hidden characters, and =TRIM(CLEAN(A2)) as your default for imported data, since it costs nothing to run both. When a line break separates words, swap it for a space with SUBSTITUTE instead of using CLEAN, and add a CHAR(160) substitution for data copied from the web. Both functions work in every version of Excel; if you're comparing versions for other text tools, see which functions Excel 365, 2021 and 2019 include and our comparison of Excel desktop vs Excel for the web.

In short: TRIM for spaces, CLEAN for the invisible, both together for imports.

Practise it#

Try the TRIM(CLEAN()) exercise on this page, then open the cleaning messy text lesson to clean a CRM export in a live sheet. You'll TRIM names, nest TRIM inside PROPER and LOWER, and use SUBSTITUTE to fix phone separators, building clean copies next to the raw data so you can compare.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

The product name in A2 came from a system export: it has extra spaces and a hidden line break at the end. In B2, clean it with CLEAN inside TRIM.

fx
ABCD
1
Raw name
Clean name
2
Desk lamp
3
Office chair
4
Monitor stand
5
6
7

Tip: Put CLEAN(A2) inside TRIM: =TRIM(CLEAN(A2)). CLEAN removes the line break, then TRIM fixes the spaces.

Practise this in a lesson

LessonCleaning messy textFix stray spaces, random capitals and inconsistent separators in imported data with TRIM, PROPER, UPPER, LOWER and SUBSTITUTE.Function guideTRIMClean imported data with Excel's TRIM: strip leading, trailing and double spaces so lookups and counts work. Examples and live practice.

Frequently asked questions

What is the difference between TRIM and CLEAN in Excel?

+

TRIM removes extra space characters: leading, trailing and repeated spaces between words. CLEAN removes the first 32 non-printing characters of the ASCII set (codes 0 to 31), such as line breaks and tabs. They fix different problems.

Does TRIM remove line breaks?

+

No. TRIM only removes the normal space character (code 32). Use CLEAN to remove a line break, or SUBSTITUTE(A2,CHAR(10)," ") to turn it into a space.

Why doesn't TRIM remove all the spaces?

+

The leftover space is probably a non-breaking space (CHAR(160)), often copied from web pages. TRIM doesn't treat it as a space. Use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).

Should I use TRIM(CLEAN()) or CLEAN(TRIM())?

+

Use TRIM(CLEAN(A2)). CLEAN runs first and removes control characters, then TRIM tidies any spaces that are left, including ones that were next to a removed character.

Does TRIM remove single spaces between words?

+

No. TRIM keeps one space between words and only removes the extras, so "Desk lamp" becomes "Desk lamp".

Sources

  • TRIM function - Microsoft Support
  • CLEAN function - Microsoft Support
  • SUBSTITUTE function - Microsoft Support

Written and checked by the ExcelReady Team. First published October 30, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. TRIM vs CLEAN at a glance
  2. How TRIM works
  3. How CLEAN works
  4. The same messy text, side by side
  5. How to see what's really in a cell
  6. What neither TRIM nor CLEAN removes
  7. How to clean a whole column
  8. When to use TRIM
  9. When to use CLEAN
  10. Common mistakes with TRIM and CLEAN
  11. Our recommendation
  12. Practise it

Keep reading

Comparisons· 6 min read

Excel 365 vs 2021 vs 2019: Which Functions You Get

Excel 2019 added IFS, SWITCH, MAXIFS, MINIFS, CONCAT and TEXTJOIN. Excel 2021 added dynamic arrays with FILTER, SORT, SORTBY, UNIQUE and SEQUENCE, plus XLOOKUP, XMATCH and LET. Microsoft 365 has all of these and keeps getting new ones, such as TEXTSPLIT, TEXTBEFORE and TEXTAFTER, which are also in Excel 2024.

Comparisons· 6 min read

Excel Desktop vs Excel for the Web

Excel for the web (often called Excel Online) runs free in a browser and handles everyday work: formulas, including XLOOKUP and dynamic arrays, tables, charts, pivot tables and co-authoring. The desktop app adds what the browser version lacks or limits, such as VBA macros, Power Pivot and the full range of advanced options, and works offline.

Text· 7 min read

Clean Messy Data in Excel With TRIM, CLEAN and PROPER

Use TRIM to remove extra spaces, CLEAN to remove hidden non-printing characters, and PROPER to put a capital at the start of each word. Nest them to fix several problems at once: =PROPER(TRIM(A2)) turns " maria gonzalez" into "Maria Gonzalez". Build the clean version in a new column, check it, then paste it as values.

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback. The first lessons are free, with no download.

Start learning for free