Clean your Excel data with TRIM, SUBSTITUTE, and other tips

Clean your Excel data with TRIM, SUBSTITUTE and other tips

In a recent project, I found myself facing an Excel table loaded with invisible spaces, duplicated entries, and non-printable characters. Impossible to sort or analyze anything without wasting a lot of time. So, I pulled out my best formulas: TRIM to get rid of unwanted spaces, SUBSTITUTE to modify portions of text, and a few extra tricks. Today, I share with you this process, the pitfalls I avoided, and additional tips to make your data as clean as a whistle.

Why clean your Excel data ?

Before diving into formulas, let’s take a moment to understand the stakes. Poorly formatted data means:

  • Incorrect or incomplete calculation results.
  • An inability to properly sort and filter your lists.
  • Biased charts.
  • Growing frustration for the user or your team.

In short, a lack of reliability that can cost dearly in time and decision-making. A clean table is the guarantee of fast and robust analysis.

Essential cleaning functions

TRIM: the anti-space weapon

The TRIM function removes all unnecessary spaces to the left and right of a text, as well as multiple spaces between words. Example:

=SUPPRESPACE(A2)

If A2 contains ” Banque de données “, TRIM(A2) returns “Banque de données”. Note: it does not remove non-breaking spaces nor invisible characters (tabs, line breaks).

SUBSTITUTE: to replace on the fly

When you need to change a word, punctuation, or recurring character, SUBSTITUTE is your best ally. Its syntax:

=SUBSTITUE(texte_original; texte_à_remplacer; texte_de_remplacement; [no_ème_occurence])

For example, to transform all semicolons into commas:

=SUBSTITUE(B2; ";"; ",")

You can also target the nth occurrence if you want to be selective. Very useful when importing a CSV file that uses an unusual separator.

CLEAN and VALUE: purify and convert

To remove non-printable characters (ASCII codes 0 to 31), use CLEAN:

=CLEAN(A3)

And if your cleaned field needs to become numeric again (for example after cleaning the currency symbol), wrap it with VALUE:

=VALEUR(CLEAN(A3))

Result: a true numeric data usable in your calculation formulas.

Additional tips and methods

1. Advanced “Find/Replace”

The classic Ctrl+H remains powerful when you know how to play with the options:

  • Wildcard mode (*, ?) for partial matches.
  • Find line breaks with Alt+010.
  • Exclude case or force format (text vs number).

A little reflex before launching a formula: inspect the ribbon and activate the checkboxes “Match case” or “Match entire cell contents” if necessary.

2. Flash Fill

Introduced in Excel 2013, Flash Fill is magical for extracting or recomposing strings. Type two examples manually, then Data → Flash Fill or Ctrl+E and let Excel generalize the rule. Note: the algorithm is based on your examples, so be precise.

3. Power Query for Advanced Cleaning

Power Query (or Get & Transform) offers a graphical interface to:

  • Split a column by separating it with a delimiter.
  • Replace multiple values in a single operation.
  • Filter rows out of range or according to a regular expression.

Once the query is configured, it refreshes with one click, ensuring consistency over time.

Combine Cleaning and Analysis

Once your data is cleaned, you can confidently tackle your summary formulas. For example:

  • Sum the values of a cleaned field (>0) with SUMIFS.
  • Count occurrences of a specific keyword in a column without stray spaces thanks to COUNTIFS.
  • Perform conditional tests on your cleaned strings with the IF function.
  • Associate a cleaned product code with a reference table via VLOOKUP.

Summary Table of Key Functions

Function Purpose Example
TRIM Remove unnecessary spaces =TRIM(A2)
SUBSTITUTE Replace one text with another =SUBSTITUTE(B2, “;”, “,”)
CLEAN Eliminate non-printable characters =CLEAN(A3)
VALUE Convert text to number =VALUE(CLEAN(B3))
Flash Fill Extract or reformat without formula Ctrl+E after 2 examples

Best Practices for Sustainable Cleaning

  • Document your transformations (tab, comments).
  • Prefer Power Query for reusable processes.
  • Save a copy before any macro or major replacement.
  • Validate your dataset with a representative sample.

Quick FAQ

Q: Which function to remove tabs?
A: Use CLEAN or directly replace the character via CTRL+H (type ALT+009 in the search box).

Q: Does TRIM remove all spaces?
A: It only handles standard ASCII spaces (code 32), not non-breaking spaces or other white characters.

Q: Can SUBSTITUTE and TRIM be combined?
A: Yes, chain them for results without residual spaces: =TRIM(SUBSTITUTE(A2,CHAR(160), ” “)).

Cleaning your Excel data is no longer a chore once you master these tools. Implement them, test on a small sample, then generalize. You will save a lot of time, avoid errors and frustrations, and your analyses will be more reliable than ever.

Thank you for reading and happy cleaning of your spreadsheets ! 🚀

Leave a comment