How to Keep Leading Zeros in Excel, and Get Them Back After a CSV Import

Keep leading zeros in Excel when you open a CSV, put them back with TEXT, and fix the #N/A lookups between 01000 and 1000. Works in Google Sheets too.

Founder, Glow Reports. , 3 min read
  • Excel
  • Data Quality
  • Formulas
Code tiles on a conveyor belt drop their first orange ring into a bin, while a glass case beside a spreadsheet keeps every ring in place
On this page
  1. Why does Excel remove leading zeros?
  2. How do you keep leading zeros when you open a CSV in Excel?
  3. How do you add the leading zeros back in Excel?
  4. Why does a lookup fail between 01000 and 1000?
  5. How do you keep leading zeros in Google Sheets?
  6. Where does Glow Reports fit?
  7. Common questions

You open a CSV export and the postcode 01000 shows as 1000. Product code 00423 is now 423, and the phone number 0612345678 has lost its first digit. Then a lookup against another file returns #N/A for half the rows. Excel read each code as a number. Numbers have no leading zeros. To keep them, import the column as Text before Excel sees it. If they are already gone, rebuild them with . A custom number format only hides the problem. Here is why it happens, the fix for each case, and the lookup trap that comes after.

Why does Excel remove leading zeros?

Excel treats any cell made only of digits as a number, and to a number, 01000 and 1000 are the same value. It converts as the file opens, so the zeros are gone before you ever see the sheet, and nothing in the cell tells you a conversion took place. The export is fine.

Microsoft lists "Remove leading zeros and convert to number" as one of the conversions Excel applies by default, and "opening a .csv or .txt file" as one of the ways it happens Microsoft Support. Typing or pasting a code into a cell does the same.

Long codes suffer a second problem. "Excel has a maximum precision of 15 significant digits", so a 16-digit card or order number loses its last digits, and long numbers show in scientific notation Microsoft Support. No format undoes that.

To check the export, open the CSV in Notepad or TextEdit instead of Excel. If the zeros are there, the file is fine and the fix belongs in how you open it. A Microsoft Tech Community thread shows the usual confusion: someone loaded the codes as text, saw the zeros, saved the file as CSV, and the zeros were gone when it was opened again Microsoft Tech Community. Most likely the saved file still held them, and Excel removed them a second time on opening.

How do you keep leading zeros when you open a CSV in Excel?

Don't double-click the file. Import it with DataFrom Text/CSV, set the code column to Text before loading, and the zeros stay. Excel never touches it.

  1. Select DataFrom Text/CSV and pick the file.
  2. In the preview, select Transform Data to open Power Query.
  3. Select the code column, then HomeData TypeText.
  4. In the Change Column Type box, select Replace current.
  5. Select .

Microsoft documents these steps for postcodes and other codes, and next month you refresh with DataRefresh Microsoft Support. Replace current matters. It swaps the automatic type step instead of adding a second one after it, and the automatic step is the one that dropped the zeros. If the preview already shows them missing, choose "Do not detect data types" in the preview's data type list, as in the guide to CSV files that open in one column.

In Excel for Microsoft 365 and Excel 2024 you can also switch the conversion off for good. Untick "Remove leading zeros and convert to number" in FileOptionsDataAutomatic Data Conversion (on a Mac, ExcelPreferencesEdit). This covers files you open, paste or type. It doesn't change Power Query imports, which follow their own type steps Microsoft Support.

How do you add the leading zeros back in Excel?

Use TEXT with as many zeros as the code has digits. turns 1000 into the text 01000 and leaves 75011 as 75011. Fill it down a helper column, then paste it over the original with Paste SpecialValues.

Microsoft gives the same pattern for postcodes and phone numbers Microsoft Support. The zero count is the length you expect:

CodeStored asFormulaResult
French postcode100001000
Product code423000423
French phone6123456780612345678

It needs a fixed length. If codes run from 3 to 8 digits by design, nothing in 423 tells you whether it was 0423 or 00423. Go back to the export and import it as Text.

A custom number format looks like a shortcut. Press Ctrl+1, select Custom and type , and 1000 displays as 01000. The cell still holds 1000. Microsoft warns that this "will not restore leading zeros that were removed prior to formatting" Microsoft Support. Fine for a printed report. It breaks the moment a formula compares the code with text from another file, because the formula reads the stored number and never sees the zero you are looking at.

MethodWhat the cell holdsUse it for
Custom format The number 1000, shown as 01000A report people only read
The text 01000Lookups, joins, files you send
Text format before typingThe text 01000Codes you type yourself

For codes you type, format the column as Text first with Ctrl+1, or start the entry with an apostrophe, . It stays hidden. The Text format "will not change numbers that have already been entered", so set it before typing Microsoft Support.

Why does a lookup fail between 01000 and 1000?

Because one side holds text and the other a number, so XLOOKUP or VLOOKUP sees two different values and returns #N/A. Make both sides the same type inside the formula, and the match comes back.

If your key lost its zeros and the reference table kept them as text, rebuild the key in the lookup:

Lookup a number key in a text column, finds 01000
=XLOOKUP(TEXT(A2,"00000"),Postcodes[Code],Postcodes[City])

If it is the other way round, a text key against a column of numbers, look up instead. Then fix the column at the source with the import above, so the next file doesn't need the patch. The other causes of #N/A, from hidden spaces to approximate matches, are in why VLOOKUP returns #N/A.

How do you keep leading zeros in Google Sheets?

The same two fixes apply. returns the code as text with its zeros Google Docs Editors Help. For display only, use FormatNumberCustom number format and type . In that format, 0 stands for "a digit in the number. An insignificant 0 will appear in the results" Google Docs Editors Help.

Same trap as in Excel. The custom format changes how the number looks, not what the cell holds, so use TEXT for any code that feeds a lookup.

Where does Glow Reports fit?

The fixes above work file by file. The work grows when a monthly report joins three exports, one with postcodes as text, one as numbers, and one where the CRM dropped the zeros on its own. The data cleaning guide covers the other checks to run before such a report.

With Glow Reports, you upload one or several CSV or Excel files and ask for the report in plain language. A CSV upload detects its separator, comma, semicolon or tab. The AI writes the SQL, builds the charts and drafts the text. The SQL sits under each figure, so you can see how a code column was read and joined, and edit the query if a postcode needs padding before the join. Reports export to PDF and stay in the workspace. The free plan gives 300 credits once, and a report costs 100 credits.

Common questions

How do I add a 0 in front of a number in Excel?

For a fixed length, use with one zero per digit. To add a single zero whatever the length, use . Both return text. That is what keeps the zero.

Why does Excel turn my long number into 1.23457E+15?

The number has more digits than Excel shows in a General cell, and beyond 15 digits Excel also drops the rest. Import the column as Text so every digit stays Microsoft Support.

Why are the zeros gone again after I save as CSV and reopen it?

The saved file usually still holds them. Excel converts the codes again each time it opens a CSV. Check the file in a text editor, then open it with DataFrom Text/CSV and the column set to Text.

Does the Text format bring back zeros that are already gone?

No. Only new entries. Use TEXT in a helper column for existing values, or reimport the original file.

El Mehdi Benane
Founder, Glow Reports

I am a product engineer and the founder of Glow Reports. I spent more than 6 years building products in tech, data and cybersecurity, for large groups, startups and SMEs. In most organizations I saw data treated as a technical topic, when it drives business decisions. I built the reporting tool I was looking for, so the people who run small and mid-sized organizations can read their own numbers without a data team.

Upload your CSV or Excel exports to Glow Reports and ask for the report, with the SQL behind each figure so you can check every join.

Keep reading