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. Text
  3. Clean Messy Data in Excel With TRIM, CLEAN and PROPER

Clean Messy Data in Excel With TRIM, CLEAN and PROPER

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

The short answer

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.

Key takeaways

  • TRIM removes spaces at the start and end and squeezes repeated spaces down to one.
  • CLEAN removes non-printing characters, such as line breaks from imported data.
  • PROPER capitalizes each word; UPPER and LOWER change every letter.
  • Nest functions to fix several problems at once: =PROPER(TRIM(A2)) or =LOWER(TRIM(B2)).
  • TRIM doesn't remove non-breaking spaces from web pages. Swap them out with SUBSTITUTE first.
On this page+
  1. Why does imported data need cleaning?
  2. How to use the Excel TRIM function
  3. How to remove hidden characters with CLEAN
  4. How to fix capitals with PROPER, UPPER and LOWER
  5. How to combine TRIM, PROPER and LOWER in one formula
  6. How to fix separators with SUBSTITUTE
  7. How to find the cells that still need cleaning
  8. How to replace the raw data with the clean version
  9. Practise it

The Excel TRIM function removes extra spaces from text, CLEAN removes hidden characters, and PROPER fixes the capitals. Together with UPPER, LOWER and SUBSTITUTE, they turn a messy export into data that sorts, matches and looks right. This guide is for anyone who has pasted a list from a CRM, a web form or another system and found stray spaces and random capitals.

Why does imported data need cleaning?#

Data copied from other systems often carries problems you can't see, and they break formulas. A name with a trailing space won't match the same name without one, so VLOOKUP returns #N/A and COUNTIF misses it. Here is a typical customer export. The spaces are real:

A: Name (raw)            B: Email (raw)                     C: State   D: Phone
"  maria   gonzalez"     "Maria.Gonzalez@Harborline.COM "   or         503.555.0142
"JAMES O'NEIL "          "JONEIL@harborline.com"            Ma         312 555 0199
"priya  shah"            "  priya.shah@Harborline.com"      wa         206.555.0177
"Chen   WEI"             "Wei.Chen@HARBORLINE.com"          MA         617 555.0123

The plan is simple: build clean copies in new columns, check them, and only then replace the raw data. That way you can always compare.

How to use the Excel TRIM function#

TRIM removes spaces at the start and end of text, and squeezes any run of spaces between words down to one. The syntax has one part:

Excel formula
=TRIM(text)

In E2, type =TRIM(A2). The result is maria gonzalez, with one space between the words and none at either end. TRIM works in every version of Excel.

To see whether a cell has extra spaces, compare its length before and after: =LEN(A2) gives 18, and =LEN(TRIM(A2)) gives 14. If the two numbers differ, TRIM has something to remove.

Why isn't TRIM removing the spaces?#

TRIM only removes the normal space character. Text copied from web pages often contains non-breaking spaces, which look the same but are a different character (number 160). Swap them for normal spaces first, then trim:

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

CHAR(160) is the non-breaking space. SUBSTITUTE replaces each one with a normal space, and TRIM tidies the result.

How to remove hidden characters with CLEAN#

CLEAN removes non-printing characters: control codes that don't show up as letters, such as line breaks inside a cell. They often arrive in data exported from other programs. The syntax:

Excel formula
=CLEAN(text)

CLEAN removes character codes 0 to 31, but not spaces, so it pairs well with TRIM:

Excel formula
=TRIM(CLEAN(A2))

Use this when cells look fine but still won't match, or when text wraps onto two lines for no visible reason.

How to fix capitals with PROPER, UPPER and LOWER#

These three change capital letters, and each takes one part, the text:

FunctionWhat it doesExampleResult
PROPERCapital at the start of each word=PROPER("chen WEI")Chen Wei
UPPEREvery letter capital=UPPER("wa")WA
LOWEREvery letter small=LOWER("JONEIL@harborline.com")joneil@harborline.com

PROPER also capitalizes the letter after an apostrophe or a hyphen, so O'Neil and El-Sayed come out right. But it doesn't know name rules: mcdonald becomes Mcdonald, and a brand like iPhone becomes Iphone. Always check cleaned names by eye.

How to combine TRIM, PROPER and LOWER in one formula#

Put one function inside another to fix several problems at once. This is called nesting, and Excel works out the inside function first. For the names:

Excel formula
=PROPER(TRIM(A2))

TRIM removes the spaces, then PROPER fixes the capitals, so " maria gonzalez" becomes Maria Gonzalez and "JAMES O'NEIL " becomes James O'Neil. For the emails, use LOWER instead:

Excel formula
=LOWER(TRIM(B2))

This gives maria.gonzalez@harborline.com, with the trailing space gone. For the states, =UPPER(C2) gives OR, MA, WA and MA. Fill each formula down (Windows: Ctrl+D; Mac: ⌘D).

How to fix separators with SUBSTITUTE#

SUBSTITUTE swaps one piece of text for another: =SUBSTITUTE(text, old_text, new_text). The phone numbers mix dots and spaces. To use dashes everywhere, replace the dots, then put that inside a second SUBSTITUTE that replaces the spaces:

Excel formula
=SUBSTITUTE(SUBSTITUTE(D2,".","-")," ","-")

All four numbers come out in the same style: 503-555-0142, 312-555-0199, 206-555-0177 and 617-555-0123. SUBSTITUTE is also how you delete a character: replace it with empty text, as in =SUBSTITUTE(D2,".","").

For a one-off fix, Find and Replace does the same job without a formula (Windows: Ctrl+H; Mac: ⌃H). It changes the cells directly, so make a copy of the data first.

How to find the cells that still need cleaning#

Before and after cleaning, it helps to know how many cells have problems. A wildcard in COUNTIF finds trailing spaces: "* " means any text that ends with a space.

Excel formula
=COUNTIF(A2:A5,"* ")

On the raw names this returns 1 (JAMES O'NEIL has a trailing space). Use " *" for leading spaces.

To flag every cell that cleaning would change, compare the raw value with the cleaned one using EXACT, which is case-sensitive:

Excel formula
=EXACT(A2,PROPER(TRIM(A2)))

FALSE means the cell needs cleaning; TRUE means it's already tidy. Filter that column for FALSE to review the rows one by one.

How to replace the raw data with the clean version#

Once the clean columns look right, turn them into plain values so they no longer depend on the raw data:

  1. Select the clean column and copy it (Windows: Ctrl+C; Mac: ⌘C).
  2. Select the first cell of the raw column.
  3. Open Paste Special (Windows: Ctrl+Alt+V; Mac: ⌃⌘V), choose Values, and confirm.
  4. Delete the helper column.

Two more checks are worth doing. Numbers that came in as text, such as "1250" sitting on the left of the cell, need =VALUE(TRIM(A2)) to become real numbers. And if you need to split cleaned names into first and last, see how to split first and last names. Pulling a company out of an email is a job for TEXTBEFORE and TEXTAFTER, and formatting numbers inside text is covered in the TEXT function guide.

The TRIM function guide is a quick syntax reference.

Practise it#

Practise cleaning messy text in a live spreadsheet: trim names, fix capitals with PROPER, UPPER and LOWER, and standardize phone numbers with SUBSTITUTE. Then take the text skill summary, where you clean a whole contact list and build a mailing line from it.

Try it yourself

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

The name in A2 has extra spaces and no capitals. Click E2 and clean it so it reads Maria Gonzalez: put TRIM inside PROPER.

fx
ABCDEF
1
Name (raw)
Email (raw)
State (raw)
Name
2
maria gonzalez
Maria.Gonzalez@Harborline.COM
or
3
JAMES O'NEIL
JONEIL@harborline.com
Ma
4
priya shah
priya.shah@Harborline.com
wa
5
Chen WEI
Wei.Chen@HARBORLINE.com
MA
6
7
8

Tip: The inside function runs first: remove the spaces, then fix the capitals.

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.LessonText skill summary: clean a contact listPractice the text module on one messy contact list: tidy names and cities with TRIM and PROPER, split out first names and companies with TEXTBEFORE, and join a mailing line with &.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 does the TRIM function do in Excel?

+

TRIM removes spaces from the start and end of text and reduces any run of spaces between words to a single space. =TRIM(" maria gonzalez") returns "maria gonzalez".

Why isn't TRIM removing spaces?

+

The spaces are probably non-breaking spaces, which often come from web pages. TRIM only removes normal spaces. Use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")) to turn them into normal spaces first.

What is the difference between TRIM and CLEAN?

+

TRIM removes extra spaces. CLEAN removes non-printing characters, such as line breaks and other control codes. Use =TRIM(CLEAN(A2)) to do both.

How do I capitalize the first letter of each word in Excel?

+

Use PROPER: =PROPER(A2) turns "JAMES O'NEIL" into "James O'Neil". Check the results by eye, because PROPER doesn't know name rules like McDonald.

How do I replace the original data with the cleaned version?

+

Copy the clean column, then use Paste Special > Values over the original (Windows: Ctrl+Alt+V; Mac: Ctrl+⌘+V). This keeps the results and removes the formulas.

Sources

  • TRIM function - Microsoft Support
  • CLEAN function - Microsoft Support
  • PROPER 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. Why does imported data need cleaning?
  2. How to use the Excel TRIM function
  3. How to remove hidden characters with CLEAN
  4. How to fix capitals with PROPER, UPPER and LOWER
  5. How to combine TRIM, PROPER and LOWER in one formula
  6. How to fix separators with SUBSTITUTE
  7. How to find the cells that still need cleaning
  8. How to replace the raw data with the clean version
  9. Practise it

Keep reading

Text· 7 min read

TEXTBEFORE and TEXTAFTER in Excel

TEXTBEFORE returns the text before a delimiter, and TEXTAFTER returns the text after it. =TEXTBEFORE(A2,"@") gives the username of an email, and =TEXTAFTER(A2,"@") gives the domain. A third argument picks which occurrence: -1 means the last one. They need Microsoft 365, Excel for the web or Excel 2024; in older Excel, use LEFT or MID with FIND.

Text· 6 min read

The TEXT Function: Format Numbers and Dates Inside Text

The TEXT function turns a number or date into text with the format you choose: =TEXT(value, format_text). For example, =TEXT(B2,"mmm d, yyyy") shows a date as Feb 3, 2025, and =TEXT(C2,"$#,##0.00") shows $1,250.50. Use it when you join numbers or dates to words, because & otherwise shows the raw stored number.

Text· 7 min read

How to Split First and Last Names in Excel

To split a full name in Excel, use =TEXTBEFORE(A2," ") for the first name and =TEXTAFTER(A2," ",-1) for the last name, which also handles middle names. In Excel 2021 and older, use =LEFT(A2,FIND(" ",A2)-1) for the first name. For a one-off job, Data > Text to Columns or Flash Fill splits names without formulas.

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