Files & formats

Excel removes leading zeros? Keep codes as text

The short answer

For codes that must keep their exact digits, format the cells as Text before entering the values. If Excel already stripped the zeros, copy the values again from the original source. Use a custom format when you only need the number to look padded in the workbook.

01Keep the original digits in new entries

Section link

Select the empty cells where the codes will go. Open Format Cells, choose Text, then type the codes or paste them from a plain-text source. For a single code entered by hand, type an apostrophe before the digits. Excel treats the entry as text. Keep long identifiers as text too, because Excel can lose digits when it stores them as numbers.

02Import the code column as text

Section link

In desktop Excel with Power Query, use Data → From Text/CSV and open the preview in the query editor. Set the code column to Text before loading it. If an automatic Changed Type step converted the codes to numbers, remove or edit that step first. Check that the preview shows the original zeros before loading the data.

03Pad the display only when the width is known

Section link

If every code in a column should have five digits, you can use the custom number format 00000 on the desktop. A cell containing 73 then shows 00073, while its stored value remains 73. When sharing exact code strings with another system, use a text column and check the exported data.

04Recover a column that has already changed

Section link

Start with the original file or a copy that still has the full codes. Changing the existing cells to Text cannot recover digits that were discarded. When the original is gone, you can reconstruct leading zeros only if you know the exact code width. For variable-width codes, verify the values against the system that issued them.

Sources & further reading

Put it into practice