Cleaning messy text: TRIM, PROPER and Flash Fill

Fix extra spaces, shouting capitals and inconsistent names — the first job with any data someone else typed.

Module 5: Text and dates · Lesson 22 of 45 · 14 min read · Free

Data typed by people is messy. Some names are in CAPITALS, some in lowercase, some have spaces before or after, some have two spaces in the middle. It looks like a cosmetic problem, but it breaks real work: "Lagos " with a trailing space is not equal to "Lagos", so SUMIFS skips it and XLOOKUP can't find it. Cleaning text is the first job with any list someone else typed.

Open m5-text-dates-practice.xlsx, sheet Customers. Column A is a mess.

The cleaning functions

FunctionWhat it does" tunde BELLO " becomes
TRIMremoves spaces at both ends; reduces inner double spaces to one"tunde BELLO"
PROPERCapital First Letter Of Each Word" Tunde Bello "
UPPERALL CAPITALS" TUNDE BELLO "
LOWERall small letters" tunde bello "
CLEANremoves invisible “non-printing” characters (from copied web pages or systems)—

They're most useful together. In E2:

=PROPER(TRIM(A2))

The inner function runs first (TRIM removes the spaces), then PROPER fixes the capitals.

TRIM and PROPER together

Replace the messy column with the clean one

A cleaning formula lives in a helper column. When you're happy with it:

  1. Select the clean column (E2:E31) → Copy (Ctrl+C).
  2. Right-click the original column's first cell → Paste Special → Values (the clipboard icon with 123).
  3. Delete the helper column.

Paste Values pastes the results, not the formulas, so deleting the helper column doesn't break anything.

Flash Fill: cleaning by example

For many patterns you don't need a formula at all.

Flash Fill fills a column from your example

Type what you want for the first row, start the second, and Excel spots the pattern. Flash Fill can:

  • pull out first names or surnames,
  • reformat phone numbers (0803-456-7812 → 08034567812),
  • join columns (Okafor, Adaeze),
  • extract codes from the middle of text.

Find and Replace

Ctrl+H opens Find and Replace — the quickest cleaner of all:

  • Replace "Abj" with "Abuja" in the whole sheet.
  • Replace two spaces with one (click Replace All a few times).
  • Replace "₦" with nothing to turn text prices back into numbers.

Click Options to limit it to the selection, match case, or match the entire cell only.

Check yourself

Answer in your head first, then open each question to see the answer and why.

  1. Why can "Lagos " (with a space at the end) cause wrong totals?

    • A Excel adds the space as a number
    • B It doesn't equal "Lagos", so SUMIFS and lookups skip it
    • C It changes the font
    • D It hides the row
    Show the answer

    B) It doesn't equal "Lagos", so SUMIFS and lookups skip it — To Excel, text with an extra space is different text. TRIM fixes it.

  2. What does =PROPER(TRIM(" ngozi EZE ")) return?

    • A "Ngozi Eze"
    • B "NGOZI EZE"
    • C " Ngozi Eze "
    • D "ngozi eze"
    Show the answer

    A) "Ngozi Eze" — TRIM removes outer spaces and extra inner spaces; PROPER capitalises each word.

  3. After cleaning names with a formula in a helper column, how do you keep just the results?

    • A Copy, then Paste Special → Values
    • B Delete the original column first
    • C Press Ctrl+`
    • D Use Format Painter
    Show the answer

    A) Copy, then Paste Special → Values — Paste Values pastes the results without formulas, so the helper column can be removed.

  4. What is the shortcut for Flash Fill?

    • A Ctrl+F
    • B Ctrl+E
    • C Ctrl+H
    • D Ctrl+L
    Show the answer

    B) Ctrl+E — Ctrl+E runs Flash Fill (Data → Flash Fill).

More free lessons: Why Excel, and how this course works · A tour of the Excel window · Number formats: naira, percentages, dates and phone numbers · Your first formulas: + − × ÷ and the order Excel follows · IF: make Excel decide · Excel Tables: the habit that saves hours · Choosing the right chart · Your first PivotTable · Printing that looks right the first time · Revision guide and how the final exam works