How to Remove Extra Spaces from CSV Cells
Stray spaces are the sneakiest CSV problem. A cell that looks like New York is actually New York — and to your import tool, your VLOOKUP, or your database, those are two completely different values. Lookups fail, duplicates appear, and categories split in two, all from spaces you can't see.
They creep in from padded exports, hand-typed entries, and copy-paste from emails. Here's how to strip them out — only the leading and trailing spaces, leaving the real words intact.
Method 1: Excel (TRIM)
- Open the CSV in Excel and insert a helper column next to the messy column (right-click the column letter → Insert).
- In the first helper cell, type
=TRIM(A2)— using the actual first data cell of the messy column.TRIMremoves leading and trailing spaces, and collapses any run of multiple spaces between words down to one. - Double-click the fill handle (the small square at the cell's bottom-right corner) to copy the formula down the whole column.
- Select the helper column → Copy (
Ctrl+C). - Right-click the original messy column → Paste Special → Values. The trimmed text replaces the originals, formulas gone.
- Delete the helper column and save the file.
TRIM, which only touches the edges.Method 2: Google Sheets
- Import the CSV into Google Sheets (File → Import).
- In a helper column, enter
=TRIM(A2)pointing at your first data cell, and fill it down the column. - Select the helper column → Copy, then Edit → Paste special → Paste values only over the original column.
- Delete the helper column and re-download as CSV (File → Download → Comma-separated values).
Method 3: Python (for the technical)
import csv
with open('messy.csv', newline='', encoding='utf-8') as f:
rows = [[cell.strip() for cell in row] for row in csv.reader(f)]
with open('clean.csv', 'w', newline='', encoding='utf-8') as f:
csv.writer(f).writerows(rows)
strip() removes leading and trailing whitespace from every cell in one pass — and the file never has to open in Excel at all.
The one-click way
Tired of helper columns? CSV Cleaner trims leading and trailing spaces from every cell automatically — along with blank rows, messy headers, and encoding problems — in one click. $9 once, yours forever.
See CSV CleanerMore CSV fixes: remove blank rows · fix headers with spaces · convert to UTF-8 · CSV won't import? · fix ragged rows · fix numbers stored as text