10 Ways to Clean Messy Data in Excel (With Formulas You Can Copy)
Remove extra spaces, duplicates and odd characters, split columns and fix capitalization in Excel using TRIM, CLEAN, SUBSTITUTE, Flash Fill, TEXTSPLIT and Power Query.
Exports from webshops, banks, CRMs and PDFs share one trait: they are messy. Extra spaces, mixed capitalization, two names in one cell and duplicate rows will break your pivot tables and lookups. Here are ten reliable techniques for cleaning data in Excel. Most work the same way in Google Sheets.
Rule zero: work on a copy, and keep the original sheet untouched. Use helper columns with formulas, then copy them and paste as values.
1. Remove extra spaces with TRIM
Hidden spaces are the main reason VLOOKUP and XLOOKUP fail. Use:
=TRIM(A2)
It removes leading and trailing spaces and reduces multiple spaces between words to one.
2. Remove invisible characters with CLEAN
Data copied from web pages or PDFs often contains line breaks and non-printing characters:
=TRIM(CLEAN(A2))
3. Replace non-breaking spaces
If TRIM does not seem to work, you probably have a non-breaking space (character 160), common in web data:
=TRIM(SUBSTITUTE(A2, CHAR(160), " "))
4. Fix capitalization
PROPER capitalizes the first letter of each word, UPPER and LOWER do the obvious:
=PROPER(TRIM(A2))
Be careful with names like "McDonald" or "van der Berg"; PROPER will produce "Mcdonald" and "Van Der Berg". Check those by hand or fix them with SUBSTITUTE afterwards.
5. Split one column into several
For "Last, First" or "City - Country" values use Data → Text to Columns and choose the delimiter. In Microsoft 365 you can also use a formula that updates automatically:
=TEXTSPLIT(A2, ", ")
In older versions, combine LEFT, FIND and MID:
=LEFT(A2, FIND(",", A2)-1)
6. Join columns back together
=A2 & " " & B2
or =TEXTJOIN(" ", TRUE, A2:C2) which skips empty cells.
7. Let Flash Fill do the pattern work
Type the result you want in the first one or two rows next to your data (say, the domain from an email address), then press Ctrl+E. Excel guesses the pattern and fills the rest. Always scan the output; Flash Fill makes confident mistakes.
8. Remove duplicates safely
Select your data and choose Data → Remove Duplicates. Pick the columns that define a duplicate (for example, email). To review duplicates before deleting them, use conditional formatting instead: Home → Conditional Formatting → Highlight Cells Rules → Duplicate Values. Or, in a helper column:
=COUNTIF($A$2:$A$500, A2)>1
Rows that return TRUE have another copy somewhere.
9. Find and replace with wildcards
Ctrl+H supports * (any characters) and ? (one character). To remove everything after a "(" in cells like "Invoice 123 (paid)", search for (* and replace with nothing. To search for an actual asterisk or question mark, put a tilde before it: ~*.
10. Use Power Query for repeated cleanups
If you receive the same messy export every week, do not repeat the manual steps. Use Data → Get Data → From Table/Range. In Power Query you can trim, change case, split columns, remove duplicates, fix data types and unpivot columns, and every step is recorded. Next week, paste the new data and press Refresh; the whole cleanup runs again.
A simple cleaning checklist
- Make a copy of the raw data.
- Trim and clean text columns.
- Fix data types: dates as dates, numbers as numbers. See our guide on dates and numbers stored as text.
- Standardize categories (use a dropdown list in future).
- Remove or flag duplicates.
- Check totals against the original to be sure that nothing was lost.
When it is not worth doing yourself
Cleaning a few hundred rows is a good use of an evening. Cleaning thousands of rows from PDFs with odd layouts can take hours. For those jobs, a clear, step-by-step workflow is worth more than any single formula. If you build the rules once, you can reuse them every month. Browse the other tools and templates in the ArchTrade Templates shop for ready-made trackers once your data is tidy.