New Tool Radar

AI for Data & Spreadsheets

How to Keep Leading Zeros in Postcodes When Cleaning a CSV in Excel

Keep leading zeros in postcodes when opening a CSV in Excel by importing the postcode column as text.

Schematic illustration for How to Keep Leading Zeros in Postcodes When Cleaning a CSV in Excel: three numbered steps - Import, do not double-click; Set postcode column to Text; Check code lengths.

Opening a CSV by double-clicking lets Excel guess each column type, and a postcode such as 02134 becomes the number 2134 with the zero gone. Importing through the Text Import wizard and setting the postcode column to Text keeps every code intact.

Prerequisites

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

Steps

  1. Do not double-click the CSV. In Excel, go to Data, Get Data, From File, From Text/CSV.
  2. In the preview, select the postcode column and set its data type to Text.
  3. Load the data, then check the postcode lengths with a LEN column and compare them with the source.
  4. If any postcode is short, re-import the file rather than adding zeros by hand.
  5. Save the imported file as .xlsx so the text format is kept.

Worked example: Fictional customer postcodes kept as text

The practice table below is a fictional five-customer postcode list. The length column is the character count of each postcode, and the total is their sum. 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.

Customer Postcode Length
Amara 02134 5
Ben 10027 5
Clara 90210 5
Dev 30301 5
Elena 60614 5
Total 25

Expected result. Five postcodes, each 5 characters long, and the lengths add to 25.

Limits

  • A postcode column formatted as Text after opening will not restore zeros already lost; re-import instead.
  • Postcodes are identifiers, never numbers, so never sum or average the column.

Sources

See all