Sub topic 1
Why Messy Text Causes Problems in Excel
Prerequisites
You should know how to enter and copy Excel formulas, use relative references such as A2, and distinguish text from numbers.
Why messy text causes problems
Imported text often looks correct but contains differences that Excel treats as meaningful. A leading space makes "North" different from " North". A line break or tab can also prevent a lookup from finding a match. Inconsistent spacing can affect sorting, duplicate checks, and comparisons.
Common problems include:
- Extra spaces at the beginning, end, or between words
- Tabs and other non-printing control characters
- Text copied from web pages with hidden non-breaking spaces
- Values split across lines inside one cell
A useful cleaning process separates the original data from the corrected result.
Cleaning with a helper column
Suppose the original text is in column A and the first value is in A2. Add a heading such as Cleaned in B1. Enter a cleaning formula in B2, then copy it down.
A helper column lets you compare the source and result row by row. It also prevents formulas from changing the original imported data.
TRIM: removing extra spaces
TRIM removes leading and trailing ordinary spaces. It also changes multiple spaces between words to one space.
=TRIM(A2)For example, text that appears as Red Chair becomes Red Chair. TRIM does not remove tabs, line breaks, or non-breaking spaces.
CLEAN: removing non-printing characters
CLEAN removes non-printing characters with character codes from 0 through 31. These include many tabs and line-feed characters commonly introduced during imports.
=CLEAN(A2)CLEAN does not fix extra ordinary spaces. For basic imported text, apply both functions:
=TRIM(CLEAN(A2))This removes control characters first, then normalizes spaces. Inspect the results before replacing the source column.
Exercise
Text in A2 contains a tab followed by three spaces before the word "West". Which formula removes both problems?
Show answer
Use =TRIM(CLEAN(A2)).