Excel Show Preceding Zeros: Keep Leading Zeros in Cells
In this article
To show preceding zeros in Excel, stop treating the value as a number: either type an apostrophe before the digits ('007), format the cell as Text before you enter the data, or apply a custom number format such as 00000 so a real number like 7 displays as 00007. Which one to use depends on whether you need the zero only for display or as actual text in a lookup, import or export.
The reason zeros disappear is simple: Excel sees 007 as the number 7, and numbers do not keep leading zeros. Every method below works around that rule in a slightly different way. Labels, ZIP codes, employee IDs, product codes, phone extensions and part numbers are the usual cases where the zero matters. Menu labels can differ slightly by Excel version, platform and region, but the features named here have been stable for years on Windows, Mac and the web version.
What You'll Need
- Excel on Windows, macOS or Excel for the web, or Google Sheets if that is what you use
- Your data either ready to type or already in a column
- A decision on whether you want the zeros just for display (real numbers underneath) or as genuine text (used in IDs and lookups)
Step-by-Step
- Pick the method before you type. If the column holds identifiers you never add or subtract, text is the right choice. If you might sort numerically or do maths, use a custom format so the underlying value stays a number.
- Quick one-off entry: click the cell, type an apostrophe, then the digits: '007. Press Enter and the cell shows 007. The apostrophe is not displayed and marks the cell as text. This is the fastest fix for a single cell but easy to forget on a large list.
- Format the column as Text first: select the column, right-click it, choose Format Cells (or press Ctrl+1 on Windows, Command+1 on Mac), pick Text in the list, and click OK. Then type 007, 0021 and so on. Text formatting must be applied before entry; numbers already entered keep their stripped zeros until you retype them.
- Custom format for real numbers: select the cells, open Format Cells, go to the Number tab, choose Custom at the bottom of the category list, and type a zero for every position you want, for example 00000 for five digits. Click OK. A cell containing 42 now shows 00042 while still behaving as the number 42 in formulas.
- Format as you type with the Text prefix: type a single quote and press Space or Enter and Excel stores the entry as text automatically, which is handy for quick scanning of long code lists.
- Fix a column already entered: if the zeros are already gone, formatting as Text alone is not enough because the value is still the number 7. Apply the custom format 00000 to restore the look, or use =TEXT(A2,"00000") in a helper column to produce a text version, then copy and paste the helper column back as values (Paste Special > Values) if you need text.
- For imported CSVs and text files: do not just double-click the file. Use Data > From Text/CSV, and in the import dialog set the column containing the codes to Text rather than General before loading. That keeps every leading zero from the source file.
- For copied data from another system: paste into a column already formatted as Text using Paste Special > Text, or use the Text Import Wizard if your version offers it.
- For a formula that adds leading zeros: combine REPT and LEN, for example =REPT("0",5-LEN(A2))&A2, which pads any value in A2 to five characters. This gives a text result, so use it only where text is acceptable.
- Check the result: click a formatted cell and look at the formula bar. If it shows 7 while the cell shows 00007, you used a number format. If it shows 007, the cell is text. Both are correct for different jobs.
Common Mistakes
- Formatting as Text after entering the data: Excel does not restore zeros that were already stripped. You must retype, or use a custom format or TEXT formula.
- Applying the custom format to a cell that already contains text: it usually still displays fine, but custom number formats are meant for numbers, so mixing the two in one column can cause sorting and lookup surprises.
- Using Excel's built-in number formats expecting a leading zero option. There is no leading zero checkbox; the Custom category is where you build it.
- Padding with the TEXT function and then wondering why =A2+1 fails: the result is text, and arithmetic on text returns errors unless Excel silently coerces it.
- Double-clicking a CSV to open it in Excel, which strips the zeros again on every open. Import it properly each time, or save a converted .xlsx copy for repeated use.
- Confusing a displayed zero with a stored zero. Copy a custom-formatted cell into another program and the zeros may vanish because the underlying value is still 7.
Tips
- Use the custom format 00000 for ZIP codes and 00000-0000 style patterns where you need a fixed look but real numeric sorting.
- Keep a separate real-number column for calculations and a formatted or TEXT column for display if a report needs both.
- The TEXT function also handles dates and currency: =TEXT(value,"format") converts and pads in one step.
- When sharing a file, tell recipients the columns are text. Most spreadsheet software respects a stored text cell, but some systems re-parse on import.
- Apostrophe entries still count as text in COUNTIF and VLOOKUP. Make sure the lookup value is also text, or the match fails silently.
- For Google Sheets, select the column, open Format > Number > Plain text, or use the custom number format menu to add zeros in the same way.
Troubleshooting
If the zeros still disappear, check whether the cell is genuinely set to Text or whether the custom format was applied to a number cell and then overwritten by a paste. Reapply the format after any paste from another source.
If a lookup returns #N/A after you add zeros, the values are probably stored as different types: one column text, one number. Convert both with the same method, for example using TEXT() on the number side, and retry.
If a formula such as REPT produces a wrong-length result, check the LEN count; negative padding lengths happen when the value is longer than the target width, so wrap it in IFERROR or skip padding for those rows.
If Excel keeps auto-converting your text entries back to numbers, set the whole column to Text before typing and avoid pasting from web pages, which can carry hidden formatting. Pasting as plain text (Paste Special > Text) prevents that.
If only some rows show zeros, inspect the formula bar for mixed types. Correcting one row at a time is often faster than debugging the lot.
Frequently Asked Questions
Why does Excel remove leading zeros?
Because a cell containing only digits is read as a number, and numbers do not store leading zeros. The zero is formatting, not the value.
Can I show zeros without turning the cell into text?
Yes. Use a custom number format such as 00000, which leaves the cell a real number for maths and sorting while displaying five digits.
Does typing an apostrophe work in Excel for the web?
Yes, the apostrophe text-prefix works in desktop Excel, Excel for the web and usually Google Sheets. It is stored as text.
Why do zeros come back after I re-open my CSV?
Because the file has no formatting and Excel re-parses it on open. Import with the column set to Text, or save a converted .xlsx copy.
How do I pad numbers to a fixed width with a formula?
Use =TEXT(A2,"00000") or =REPT("0",n-LEN(A2))&A2, where n is the target width. Both return text.
Will custom-formatted zeros survive a copy to another app?
Not always. Number formatting is part of the workbook, not the value, so pasting elsewhere may show the bare number instead.