How to Stop Excel from Removing Leading Zeros
In this article
Excel strips leading zeros because it treats any entry that looks like a number as a number, and numbers do not keep leading zeros. To stop this, either format the cells as Text before you type, or enter the value with an apostrophe in front (like '00123), or use a custom number format such as 00000 when you need the zeros to display but still want the cell treated as a number. For data you are importing, set the column format to Text during the import rather than after. The method you pick depends on whether you need the zeros for display only or for the underlying value to stay text.
What You'll Need
- Excel for Windows, Excel for Mac, or Excel for the web (menu labels can differ slightly by version and platform; the steps below are written for the desktop app and note where the web version differs).
- The data you want to preserve, either already typed, pasted from elsewhere, or about to be imported from a CSV or text file.
Step-by-Step
- Decide what the zeros are for. If the value is an identifier (ZIP code, employee ID, product code, phone extension), it should be stored as text. If it is a number you will calculate with (a part number that happens to have leading zeros but is still numeric), use a custom format so the zeros show but the value stays numeric. This choice determines which method below to use.
- Format the cells as Text before typing (best for identifiers). Select the column or cells, right-click and choose Format Cells (or press Ctrl+1 on Windows, Cmd+1 on Mac). On the Number tab, choose Text and click OK. Now type
00123and Excel keeps it exactly as typed. In Excel for the web, select the cells, open the Home tab, use the number format dropdown and choose Text. - Or type an apostrophe first. Typing
'00123tells Excel to treat the entry as text. The apostrophe is not displayed in the cell and does not appear in the formula bar as part of the value. This is the fastest fix for a few cells, but it is easy to forget on a long list. - Or apply a custom number format (best when the value must stay numeric). Select the cells, open Format Cells, choose Custom on the Number tab, and type a format with the right number of zeros, for example
00000for five-digit codes. The underlying value stays a number, so calculations still work, but the display keeps the zeros. - Fix data you already pasted. If the zeros are already gone, you cannot recover them by reformatting alone, because Excel stored the number without them. Re-paste the original data: first format the destination column as Text, then paste. If you are pasting from a web page or another program, use Paste Special and choose Text or Unformatted Text so Excel does not reinterpret the values.
- Set the column to Text during a CSV or text import. When you open a CSV with Data > From Text/CSV (or the older Text Import Wizard), you get a preview. Use the column type dropdown or the wizard step that lets you set each column's format, and choose Text for the columns with leading zeros before you click Load or Finish. This is the only reliable way to keep zeros in imported files, because changing the format after import is too late.
- Check the result. Click a cell and look at the formula bar. If the zeros appear in the cell but not in the formula bar, you have a custom format and the value is numeric. If the zeros appear in both, the cell is text. Either can be correct; just make sure it matches what step 1 decided.
Common Mistakes
- Formatting after typing. Changing a cell to Text after Excel has already stored
00123as123does not bring the zeros back. The format only affects how the stored value is displayed; the stored value has already lost the zeros. - Using Text format for numbers you need to calculate. Text values are ignored by SUM and similar functions. If you need arithmetic, use the custom format instead.
- Pasting as plain text into a General-formatted column. Even if the source has zeros, a General column will strip them on paste. Format first, paste second.
- Assuming the import preview is optional. Clicking through the CSV import without setting column types is the most common reason zeros vanish from imported files.
- Confusing display with storage. A custom format shows zeros but the cell value is still
123. If you export that column to another system, the zeros may disappear again. For identifiers that leave Excel, store them as text.
Tips
- If you have a whole column of identifiers, format the entire column as Text before pasting, not just the visible cells. Excel applies the format to cells you have not filled yet.
- For ZIP codes specifically, the custom format
00000handles five-digit codes, but nine-digit ZIP+4 codes need00000-0000. Text format is simpler if you mix both. - When sharing a workbook, tell recipients that identifier columns are Text. If they retype a value into a General cell, the zeros will vanish on their machine.
- Use Data > From Text/CSV rather than double-clicking a CSV file. Double-clicking opens it with default settings and skips the column-type step.
- If you only need the zeros for a printed report, the custom format is enough and keeps the sheet sortable and calculable.
Troubleshooting
If the zeros still disappear after formatting as Text, check that you formatted the cells before entering the data. Re-enter one value to test; if it holds, the format is working and the earlier entries need retyping or re-pasting. If a custom format shows more or fewer zeros than expected, open Format Cells and count the zeros in the format string; each zero is one displayed digit. If imported data loses zeros despite setting the column to Text in the preview, confirm you set the type for the correct column and that the delimiter is detected properly, because a misread delimiter shifts columns and applies the wrong format. If formulas return errors after converting a column to Text, that is expected: text values cannot be summed. Switch those cells to a numeric format or use VALUE() to convert them where appropriate. If the file is opened by another program or exported, test the export and check whether the receiving system treats the field as text; if it does not, the zeros may be lost downstream regardless of Excel settings.
Frequently Asked Questions
Why does Excel remove leading zeros?
Excel treats any entry that looks like a number as a number, and numbers do not store leading zeros. The zeros are discarded at entry, not hidden.
Can I get the zeros back after they are gone?
Not by reformatting. The stored value no longer contains them. Re-enter or re-paste the original data into cells formatted as Text.
What is the difference between Text format and a custom format like 00000?
Text stores the zeros as part of the value but the cell cannot be used in calculations. A custom format displays zeros while keeping a numeric value, so calculations still work.
Does the apostrophe trick work in Excel for the web?
Yes, typing an apostrophe before the value treats it as text in Excel for the web as well as the desktop app.
How do I keep leading zeros when opening a CSV?
Use Data > From Text/CSV and set the relevant columns to Text in the preview before loading. Opening the file by double-clicking skips that step.
Will formatting a column as Text affect existing numbers in it?
It changes how they are treated going forward. Existing numeric values stay numeric until re-entered, and new entries in that column are stored as text.