Excel Deletes Leading Zeros: 5 Fixes That Stick

Excel cell showing an ID with its leading zeros preserved

If Excel keeps deleting 0 in front of an entry such as 00127, the cell is usually being treated as a number, so Excel drops the zeros that do not change its value. This often happens when you type or paste an ID, ZIP code, or account number into a cell formatted as General.

Why this happens

Excel stores numeric values as numbers, not as the exact characters you typed. Leading zeros are not meaningful to arithmetic, so they disappear when Excel converts digit-only text into a number. The zeros can also be lost earlier, when a file is imported or transformed.

  • Automatic conversion: General-formatted cells interpret digit-only entries as numbers.
  • Import inference: Excel or Power Query may detect a column as numeric and convert text codes.
  • Downstream formatting: Word, Outlook, or PDF automation may receive a numeric value rather than the original text.
CauseSymptomQuick test
General cell formatZeros vanish after entryClick the cell and check the formula bar for the shorter value
Numeric importZeros are missing as soon as the file opensInspect the imported column's data type
Display format onlyZeros show in Excel but not in a merge or exportCheck whether the stored value is numeric

1. Format the cells as Text before entering data

Select the destination cells or entire column, then choose Home > Number Format and select Text. Type or paste the values again; existing numbers will not regain zeros just because you change their format. A green triangle or a text indicator may appear, and the formula bar should show the full entry, such as 00127.

2. Prefix individual entries with an apostrophe

For a one-off value, type an apostrophe before the code, for example '00127. Excel uses the apostrophe to treat the entry as text and does not display the apostrophe in the cell. Confirm by selecting the cell and checking that the formula bar retains the leading zeros.

3. Apply a custom number format for fixed-width codes

If the values are numeric but should always display at a known width, select the cells and open Format Cells with Ctrl+1. On the Number tab, choose Custom and enter a format such as 00000 for five-digit display. A value of 127 then appears as 00127, while the stored value remains 127. This works for display, but downstream systems may still receive 127, so use text for identifiers that must retain the literal zeros.

4. Import the column as text in Power Query

When bringing in a CSV or workbook, choose Data > From Text/CSV (or the relevant import command) and select Transform Data. In Power Query, select the identifier column and set Data Type to Text; remove or edit an automatically added Changed Type step if it converted the column to a number. Choose Close & Load. The loaded cells should show the original zeros, and a refresh should preserve them.

5. Repair existing values with a formula

If every code has a known fixed width, use =TEXT(A2,"00000") to convert the numeric value in A2 to five-character text with leading zeros. Fill the formula down, then copy the results and use Paste Special > Values if you need a standalone text column. Check a short value and a full-width value to confirm both have the intended length.

6. Check Word, Outlook, and PDF automation

If zeros appear in Excel but disappear in a mail merge, template, or PDF output, check the value passed to the automation step. Use a text column as the merge or export source, and avoid converting the identifier to a number in code or a connector. For a Word mail merge, the Excel source should contain text values; reconnect or refresh the recipient list after changing the source. Test one record with leading zeros through the complete workflow and confirm the final document or PDF retains them.

FAQ

Why does Excel remove the first zero from a ZIP code?

Excel commonly interprets a digit-only ZIP code as a number, and numbers do not retain leading zeros. Store the ZIP code as text, or use a custom format if you only need a fixed-width display in that workbook.

Can I restore zeros after Excel has deleted them?

Only if you know the intended width or can recover the original source value. Use a custom format to display a fixed width, or use TEXT to create a text value; otherwise, retrieve the original data because Excel cannot infer how many zeros were removed.

How do I stop Excel from deleting leading zeros in a CSV?

Import the CSV through Data > From Text/CSV and set the relevant column to Text in Power Query before loading. Opening a CSV directly can trigger automatic type conversion, so check the imported values before saving or using them elsewhere.

To keep identifiers intact, store them as text at the point where they enter Excel and verify the value again after each import or export. If none of these fixes works, trace one affected record from the source file through Power Query and the final Word, Outlook, or PDF step to find where it changes.

Photo: Aleks Dorohovich aleksdorohovich / CC0 (Wikimedia Commons)

Leave a Comment