How to Clean CSV Data in Excel: Step-by-Step Guide
In this article
Cleaning CSV data in Excel means fixing the problems that appear when a plain-text file lands in a spreadsheet: split dates, leading zeros stripped from ZIP codes, duplicate rows, stray spaces, inconsistent capitalisation and numbers stored as text. You can do most of it with built-in tools — Text to Columns, Remove Duplicates, TRIM, Find & Replace and Power Query — without installing anything. Before you start, make a copy of the original CSV and work on the copy, because several steps below overwrite data and Excel's undo history disappears when you close the file.
What You'll Need
- Microsoft Excel for Windows or Mac (the steps below use the desktop app; the web version has fewer data tools).
- The original CSV file, kept untouched as a backup.
- A working copy saved as .xlsx so formatting and formulas are preserved.
- Optional: Power Query, built into Excel 2016 and later, for repeatable cleaning.
Step-by-Step
- Open the CSV correctly. Do not double-click the file if it contains dates or leading zeros. Instead, open Excel, go to File > Open, choose the CSV, and in the Text Import Wizard (Windows) or the import dialog (Mac) set the delimiter to comma and mark columns that must stay as text — ZIP codes, phone numbers, IDs — as Text. This prevents Excel from turning 01234 into 1234 or 1-2 into a date. Menu labels vary slightly by Excel version and region.
- Save as .xlsx immediately. Use File > Save As and choose Excel Workbook. CSV has no formatting, formulas or multiple sheets, so any cleaning you do in a CSV will be lost or flattened on save.
- Make a backup sheet. Right-click the sheet tab, choose Move or Copy, tick Create a copy. Keep this untouched copy so you can compare before and after.
- Remove fully blank rows and columns. Select the data range, press Ctrl+G (Windows) or Cmd+G (Mac), choose Special > Blanks, then right-click a row or column header and delete. For blank rows only, use Data > Filter, filter for blanks in a key column, and delete the visible rows.
- Trim stray spaces. In an empty column next to your data, enter
=TRIM(A2)(replace A2 with your first cell). Fill down, copy the results, then paste as values over the original column. TRIM removes leading, trailing and repeated internal spaces but not non-breaking spaces; for those use=SUBSTITUTE(A2,CHAR(160)," ")first. - Standardise text case. Use
=PROPER(A2)for names and titles,=UPPER(A2)for codes, or=LOWER(A2)for email addresses. Paste as values when done. - Fix numbers stored as text. Select the column, then use Data > Text to Columns and click Finish without changing anything — this forces Excel to re-evaluate each cell. Alternatively, multiply the column by 1 in a helper column. Watch for cells with a green triangle warning; click the warning and choose Convert to Number.
- Split combined columns. Select the column, then Data > Text to Columns > Delimited and choose the separator (comma, space, semicolon). For names, Delimited > Space works for two-part names but breaks on middle names — check the preview before finishing.
- Remove duplicate rows. Select the whole data range, then Data > Remove Duplicates. Tick only the columns that define a duplicate (for example email address) rather than all columns, or near-duplicates with a different timestamp will survive.
- Find and replace inconsistencies. Press Ctrl+H (Windows) or Cmd+H (Mac). Replace variants such as "NY" and "N.Y." with a single value, or replace multiple spaces with one. Use Options to match case or whole cells only.
- Handle errors and blanks in key fields. Use Data > Filter to show blanks or
#N/Avalues in required columns, then either fill them from a lookup table or delete those rows if the field is mandatory. - Check date formats. If dates imported as text, select the column and use Data > Text to Columns, choose Date and the correct order (DMY or MDY) in step 3. Confirm by checking a known date such as 31/01 versus 01/31.
- Use Power Query for repeatable cleaning. Select your range and choose Data > From Table/Range. In Power Query, use Transform to trim, change type, remove duplicates and split columns. Then Close & Load. Next month, drop the new CSV in and click Refresh — the cleaning steps replay automatically.
- Save and spot-check. Save the .xlsx, then compare a random sample of rows against the original CSV to confirm nothing shifted or was lost.
Common Mistakes
- Double-clicking the CSV, which lets Excel guess column types and silently strips leading zeros from ZIP codes and product IDs.
- Cleaning the CSV and saving as CSV, which discards formulas and formatting.
- Using Remove Duplicates across all columns, so rows that differ only by a timestamp are kept.
- Forgetting that TRIM does not remove non-breaking spaces copied from web pages.
- Deleting rows without a backup, then discovering the filter was hiding data you needed.
- Assuming a date column is correct because it looks right — 03/04/2025 is ambiguous until you set the format explicitly.
Tips
- Keep the raw CSV in a separate folder and never edit it directly.
- Work in a helper column, paste as values, then delete the helper — this keeps an audit trail until you are sure.
- Use Ctrl+Shift+L (Windows) or Cmd+Shift+L (Mac) to toggle filters quickly.
- For files over a few hundred thousand rows, Power Query is faster and less crash-prone than worksheet formulas.
- Freeze the header row with View > Freeze Panes so you can check column meanings while scrolling.
Troubleshooting
All data lands in one column. The delimiter is wrong. Reopen via Data > From Text/CSV and choose the correct separator (comma, semicolon or tab).
Leading zeros keep disappearing. Format the column as Text before importing, or prefix values with an apostrophe. Changing the format after import will not restore zeros already lost — re-import from the backup.
Dates show as numbers like 45000. The column is formatted as General. Select it and apply Home > Number Format > Short Date.
Remove Duplicates deletes too much. Undo immediately (Ctrl+Z), then repeat with only the identifying columns ticked.
Excel freezes on a large file. Close other workbooks, then use Power Query or open the CSV in a database tool first. Splitting the file into smaller chunks also helps.
Formulas show as text. The cell is formatted as Text. Change the format to General, then re-enter the formula by pressing F2 and Enter.
Frequently Asked Questions
Can I clean a CSV without changing the original file?
Yes. Open the CSV, immediately use Save As to create an .xlsx copy, and do all cleaning there. The original CSV stays untouched as your reference.
Why does Excel change long numbers to scientific notation?
Excel treats numbers longer than 15 digits as numeric and rounds them. Import those columns as Text, or prefix the value with an apostrophe, to keep account and tracking numbers intact.
Does Remove Duplicates work across multiple sheets?
No. It works on one selected range at a time. Combine sheets first (copy the rows into one sheet or use Power Query's append feature), then remove duplicates.
What is the fastest way to clean the same CSV every month?
Set up a Power Query connection once. Each month, replace the source file and click Refresh; the trim, split and type-change steps run again automatically.
Can I undo cleaning steps after saving?
Only until you close the file. Once saved and closed, undo history is gone, which is why the backup sheet and untouched CSV matter.
Is the web version of Excel enough for cleaning CSV data?
It handles basic edits, filters and some formulas, but Text to Columns, Power Query and Remove Duplicates are limited or missing. Use the desktop app for full cleaning.