Excel Automation13 min read

Excel Data Cleaning: The Checks That Actually Matter

Most “bad data” is not wrong — it is written differently. The list below is the set of defects that break lookups, comparisons and summaries, with the formula to detect each one.

Short answer

Clean Excel data in a fixed order: strip the structure first — header rows, blank rows, merged cells — then the text with TRIM, CLEAN and SUBSTITUTE for non-breaking spaces, then the data types so numbers and dates are not stored as text, and finally the categories, by auditing the distinct values in every column people type into. Cleaning in the reverse order wastes work, because a conversion fails on a value that still contains a stray character.

Before the checklist: the four functions

FunctionRemovesDoes not remove
TRIMLeading and trailing ordinary spaces, and runs of spaces inside a valueNon-breaking spaces, line breaks, any non-space character
CLEANThe first 32 non-printing ASCII characters — line breaks, tabs, control charactersNon-breaking spaces, or any visible character
SUBSTITUTEWhatever you tell it to — including CHAR(160), the non-breaking spaceNothing, unless you name it
VALUENot characters — it converts a text value that looks like a number into a numberAnything that is not a numeric value once cleaned
The combination that catches most text problems: UPPER(TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," "))))

The checklist

Work down the list in order. Each row gives you the check that detects the defect and the fix that resolves it.

#DefectHow to detect itFix
1Title or header rows above the tableThe headers are not in row 1Delete the rows above; the headers must be a single row at the top
2Blank rows inside the dataGo To Special → Blanks on the key columnDelete the entire blank rows — they break sorts, filters and Table conversions
3Merged cellsA merged range holds its value in the top-left cell only; everything else reads as blankUnmerge everything before doing anything else
4Trailing or leading spaces=LEN(A2)-LEN(TRIM(A2))Wrap the value in TRIM
5Non-breaking spacesTRIM does not change the length, so the test above still reports a difference=SUBSTITUTE(A2,CHAR(160)," ")
6Line breaks inside a valueThe value wraps in the cell when it should not=CLEAN(A2)
7Numbers stored as text=ISTEXT(A2)Clean the characters, then VALUE
8Dates stored as text=ISNUMBER(A2)DATEVALUE, or re-import with the type set explicitly
9Leading zeros lostA code that should be five characters is fourFormat the destination as Text before importing; TEXT(A2,"00000") if you must repair afterwards
10Inconsistent caseThe same value appears as ABC, Abc and abcUPPER for codes; use PROPER carefully for names — it will change ABC Traders to Abc Traders
11Inconsistent category valuesSort a distinct list and read itMap them to one form with a lookup table, not with a series of nested IFs
12Duplicate rows=COUNTIF($A:$A,$A2)>1Mark and review; remove only after deciding which row survives
13Negative amounts written as (1,000)=ISTEXT(A2)Strip the brackets with SUBSTITUTE and convert with VALUE
14Amounts carrying a currency symbol or separators=ISNUMBER(A2)=VALUE(SUBSTITUTE(SUBSTITUTE(A2,"₹",""),",",""))
15One field that should be two“Shree Balaji Enterprises — SB/0417” in a single columnText to Columns, or Power Query's split column by delimiter

The order is not arbitrary

Step 9 depends on step 7, which depends on steps 4 to 6. Converting a text value to a number fails if the value still contains a stray character, and stripping characters from a value that has already been converted to a number does nothing. This is why “clean it up” is easier to say than to do — the order matters.

The most valuable step: audit the distinct values

Of everything on the checklist, one step catches more real problems than the rest combined: listing the distinct values in every column a person types into, with a count of how often each appears.

1

Build the distinct list

Either a PivotTable with the column in Rows and a count in Values, or the UNIQUE function in newer versions of Excel. The PivotTable approach works in every version and gives you the counts alongside.
2

Sort by the count, descending

The high-count values are your real categories. The low-count values at the bottom are where the problems are — a category used once is usually a typo or a stray entry.
3

Read the short list carefully

This is where you find four vendors written forty-seven ways, three ledger heads that are the same account, and a branch code that exists only in one month's data.
4

Map to a canonical list

Build a small lookup table of source value against standard value, and apply it with XLOOKUP. A mapping table is maintainable; a chain of nested IFs is not, and it is wrong within a month.
Vendor as writtenCountStandard
Shree Balaji Enterprises184Shree Balaji Enterprises
SHREE BALAJI ENT.37Shree Balaji Enterprises
Shree Balaji Ent22Shree Balaji Enterprises
Shree Balaji Enterprise15Shree Balaji Enterprises
Shree Balaji Enterprises Pvt Ltd9Shree Balaji Enterprises Pvt Ltd
Shree Balaji Enterprieses1Shree Balaji Enterprises
Shree Balaji Enterpises1Shree Balaji Enterprises
Four real vendors hiding in seven spellings. Any summary by vendor before this step is wrong.

This defect does not look like a defect

Every one of those rows is a valid-looking entry. Nothing is blank, nothing is obviously malformed, and no formula returns an error. Sorting by count is the only way to see it, which is why building the distinct list is worth doing first on any column you are about to summarise or match on.

Never clean in place

Cleaning overwrites values, and overwriting values makes errors unrecoverable. Work in a copy, or in adjacent helper columns, so the original always survives.

ApproachWhen it is rightWhat it costs
Helper columns beside the dataYou want to see the before and after side by sideExtra columns in a sheet other people use
A separate cleaned sheetYou are preparing data for a comparison or an importThe cleaned copy must be refreshed when the source changes
Power QueryYou will do this againA short learning curve, and the source has to be a file or a table

Keeping the original is not sentimentality. When a cleaned figure is questioned — and it will be — the ability to show what the source actually said is the difference between an explanation and an argument.

A worked example

A vendor sends a statement of account as a spreadsheet. Nine columns, forty rows of headers and totals in awkward places, and this is what a clean version of it involves.

  1. 1Delete the first six rows above the header and the two total rows at the bottom.
  2. 2Unmerge the merged cells in the header block that were used to make the layout look tidy.
  3. 3Delete row 14, which is entirely blank and splits the data in two.
  4. 4Strip the non-breaking spaces from the invoice number column — the export came from a PDF and every key carries one.
  5. 5Convert the amount column from text, after removing the rupee symbol and the thousands separators.
  6. 6Convert the date column from text to real dates so that a date-range filter works.
  7. 7Trim the vendor name column and map the four spelling variants to one.
  8. 8Check that the total row you deleted agrees with the sum of the cleaned data — if it does not, you have removed a row that was not a total.

Step eight is the one people skip, and it is the only step that proves the cleaning did not alter the numbers. Always compare a total from the original against a total from the cleaned version.

Common mistakes

  • Cleaning in the wrong order. Converting types before removing stray characters is the most common sequence error, and it produces silent failures because the conversion returns an error that people then overwrite.
  • Fixing the symptom and not the source. If the same export needs the same cleaning every month, the useful fix is either a Power Query that replays it, or a conversation with the supplier about the export format.
  • Assuming a cleaned column is correct because the formulas worked. A lookup that returns a result has found something — not necessarily the right thing.
  • Deleting the original. Then nobody can prove what the source said.
  • Using PROPER on everything. It is sensible for personal names and actively harmful for identifiers, codes and anything containing an acronym.
  • Not cleaning at all before a comparison. Most “missing” records in a reconciliation are present on both sides and written differently.

Cleaning once, rather than every month

Every step above can be done with formulas in a helper column, and for a one-off task that is entirely reasonable. The problem is the second month, when the same export arrives with the same defects and the same helper columns have to be rebuilt or copied forward with the references shifted.

Power Query removes that repetition — you define the cleaning steps once and replay them. Power Query in Excel covers how. And if the cleaned data is on its way into a reconciliation, the defects worth fixing are the ones that affect the match key — which is what the Piloteq Automate workflow page is about.

If you would rather not build this by hand

Stop cleaning the same file every month

Piloteq Automate works on the files as they arrive and applies consistent matching rules, so the same defects in the same export do not have to be corrected by hand before every reconciliation.

  • ✓Rules applied identically to both files
  • ✓Exact, tolerance and last-digit matching
  • ✓No helper columns left in the source sheets
  • ✓Results with a reason recorded per record
₹1,499 · Single PC License · 12-month license

See how Piloteq Automate fits into a workflow →

Frequently asked questions

What is the correct order to clean data in Excel?+

Fix structure first, then text, then types, then categories. Remove header rows and blank rows, unmerge cells and unpivot anything that should be a row; then strip stray characters and standardise case; then convert numbers and dates that arrived as text; then audit the distinct values in your category columns. Doing it in the reverse order wastes work, because a conversion may fail on a value that still contains a stray character.

What is the difference between CLEAN and TRIM in Excel?+

TRIM removes leading and trailing ordinary spaces and reduces runs of spaces inside a value to a single space. CLEAN removes the first thirty-two non-printing ASCII characters, such as line breaks and control characters. Neither removes a non-breaking space, which is character 160 and arrives frequently when data is copied from a web page or a PDF — that needs SUBSTITUTE with CHAR(160).

Why does Excel treat my numbers as text?+

Because of where the data came from. Exports from PDFs, web pages and some accounting systems write numbers as text, and any value containing a stray space, a currency symbol or a comma inside a text-formatted cell stays text. The quickest test is alignment: numbers sit right-aligned by default and text sits left-aligned. The fix is to remove the offending characters and then convert with VALUE, or to clean the column in Power Query where the type change is explicit and replayed.

How do I stop Excel from removing leading zeros?+

Format the destination column as Text before you paste or import, and the zeros are preserved as characters. If the data is already in, converting with a formula requires TEXT with a fixed length — for example TEXT(A2,"00000") — but you have to know how many digits the field should be, which is why preventing the loss at import is the better solution.

How do I find inconsistent values such as the same vendor spelled several ways?+

Build a distinct-value list and count the occurrences. You can do this with a PivotTable on the column, or with the UNIQUE function in newer versions of Excel. Sort by the count and read the short list. Forty-seven spellings of four vendors is a very common finding, and it is the single most valuable cleaning step because it affects every summary you will ever produce.

Should I clean data with formulas or with Power Query?+

If you will do this again next month, use Power Query. It records the cleaning steps and replays them, so the work is done once rather than repeated. Formulas are fine for a one-off, but they leave a set of helper columns in the sheet that somebody will eventually delete, and next month you rebuild them.

Related guides