New Tool Radar

AI for Data & Spreadsheets

How to Clean Trailing Spaces from Names in a CSV in Excel

Remove trailing spaces from names in a CSV with TRIM so lookups and filters match the names they should.

Schematic illustration for How to Clean Trailing Spaces from Names in a CSV in Excel: three numbered steps - Add a TRIM helper column; Paste values over original; Test a lookup.

A name with a trailing space looks identical to the same name without one, but to Excel they are different values, so a lookup fails and a filter splits one person into two. TRIM removes leading and trailing spaces, and pasting the result as values makes the fix permanent.

Prerequisites

  • Excel
  • The CSV opened in Excel
  • A copy of the source file, so the original stays untouched.

Steps

  1. Add a helper column beside the name column with the formula =TRIM(A2), adjusted to the name column.
  2. Copy the helper column down, then check that the trimmed names look right.
  3. Copy the helper column and use Paste Special, Values, over the original name column.
  4. Delete the helper column, then test a lookup or filter on a name that failed before.
  5. Save the file as .xlsx so the cleaned values are kept.

Worked example: Fictional volunteer names after trimming

The practice table below is a fictional five-volunteer list after trimming. The count column is 1 per volunteer, and the total is the number of volunteers. The table below is fictional practice material, with fictional values. It is the expected result, worked out by hand, not a run of any tool.

Name Count
Amara Okafor 1
Ben Whitfield 1
Clara Jensen 1
Dev Patel 1
Elena Rossi 1
Total 5

Expected result. Five names trimmed, each counted once, and a lookup on any name now finds its row.

Limits

  • TRIM removes only standard spaces, so a non-breaking space from a web export needs CLEAN or Find and Replace as well.
  • TRIM also reduces multiple spaces between words to one, which is usually wanted but should be checked on names with double surnames.

Sources

See all