Excel Keeps Dropping Leading Zeros? Fix It
In this article
Excel drops leading zeros because it treats anything that looks like a number as a number, and numbers do not keep zeros in front of them. To stop it, format the cells as Text before you type or paste, or type an apostrophe before the value. For CSV imports, use the Text Import Wizard or Power Query and set the column to Text. For existing data, use a custom number format like 00000 or a formula to pad the zeros back on.
What You'll Need
- Excel for Windows, Mac, or the web (steps are for desktop; the web version has fewer import options).
- The data you want to keep, either already in the sheet or ready to paste or import.
- For CSV files: the original file, not a copy that has already been opened and saved by Excel.
Step-by-Step
- Decide the fix based on how the data arrives. If you are typing values by hand, use Text format or an apostrophe. If you are pasting from another program, use Paste Special or pre-format the column. If you are opening a CSV, use the import route. If the zeros are already gone, use a formula or custom format to put them back.
- Pre-format cells as Text for manual entry. Select the column or range, right-click and choose Format Cells (or press Ctrl+1 on Windows, Cmd+1 on Mac). On the Number tab, choose Text, then click OK. Type 00123 and it stays 00123. Note that menu labels can differ slightly by version and region.
- Use the apostrophe trick for one-off entries. Type an apostrophe before the value, like '00123. Excel stores it as text and hides the apostrophe. This works in any cell without changing formatting, but it is tedious for large lists.
- Paste as text to stop auto-conversion. Copy your data, then right-click the destination cell and use Paste Special > Values, or first format the destination column as Text and then paste. If you paste normally into a General-formatted column, Excel converts 00123 to 123 on contact.
- Import CSVs through the Text Import Wizard (Windows). Do not double-click the CSV. Open Excel, go to Data > From Text/CSV (or File > Open and choose Text Files), select the file, and in the preview click Transform Data or Load. In the Power Query editor, select the column with the codes, set its data type to Text, then click Close & Load. On Mac, use Data > Get Data (Power Query) > From Text/CSV and set the column type to Text before loading.
- Use a custom number format when the value must stay numeric. Select the cells, press Ctrl+1, choose Custom, and enter a format with enough zeros for your longest code, for example 00000 for five-digit codes. The cell still behaves as a number, but displays 00123. This is the right choice for ZIP codes, employee IDs, and product codes you may need to sort or calculate with.
- Pad existing values back with a formula. If the zeros are already gone, use =TEXT(A2,"00000") for a fixed width, or =REPT("0",5-LEN(A2))&A2 for a dynamic width. Copy the formula down, then copy the results and use Paste Special > Values over the original column if you want to replace it.
- Save the result in a format that keeps text. If you save as CSV, Excel writes the text values with their zeros, but reopening the file the same way will strip them again unless you repeat the import step. Saving as .xlsx keeps the formatting and text settings intact.
Common Mistakes
- Formatting after typing. Changing a cell that already contains 123 to Text format does not bring the zeros back. The value is already a number; you must re-enter it or use a formula.
- Double-clicking a CSV. This is the most common cause of lost zeros. Excel opens CSVs with General formatting and converts every numeric-looking field. Always import through Data > From Text/CSV instead.
- Using the wrong number of zeros. A custom format of 00000 applied to a six-digit code shows the full code, but applied to a four-digit code shows 01234. Match the format width to your longest value, or use a formula that pads to a fixed length.
- Assuming Text format survives everything. Text-formatted numbers cannot be summed or used in arithmetic without conversion. If you need both display and calculation, use the custom format instead.
- Pasting into a General column. Even if the source has leading zeros, pasting into an unformatted column converts them. Format the destination first or use Paste Special > Values after setting the column to Text.
Tips
- Set the entire column to Text before pasting a list of codes. It is faster than fixing individual cells afterward.
- For ZIP codes, phone numbers, and account numbers, Text format is usually the right choice because you never do math on them.
- If you regularly import the same CSV, build a Power Query query once and refresh it instead of re-importing by hand. The column types you set are remembered.
- Use =TEXT(A2,"00000") when you need a fixed-width display but still want to keep the original numeric column for sorting.
- When sharing a workbook, tell recipients not to re-save it as CSV if the leading zeros matter; CSV strips formatting on the next open.
Troubleshooting
The zeros still disappear after formatting as Text. Check that you formatted the cells before entering the data. If the value was already numeric, delete it, format the cell, and retype it. Also confirm you are not pasting over the formatted cell with a normal paste, which can reset formatting.
The CSV import preview shows the zeros but they vanish after loading. The column type was not set to Text in the preview or in Power Query. Re-run the import and change the data type for that column before clicking Load.
The custom format shows the wrong number of zeros. Open Format Cells > Custom and count the zeros in the format string. Add or remove zeros to match your longest code. A format of 00000 will not add zeros to a value that is already longer than five digits.
Formulas return #VALUE! after padding. The padded result is text, so arithmetic on it fails. Keep a separate numeric column for calculations and use the text column only for display or export.
Zeros return after reopening a saved CSV. This is expected: CSV stores plain values, and Excel re-converts them on open. Keep the master file as .xlsx and export to CSV only when needed, or re-import with the Text column setting each time.
Frequently Asked Questions
Why does Excel remove leading zeros?
Excel treats entries that look like numbers as numbers, and a number cannot have leading zeros. The value 00123 is stored as 123. Formatting the cell as Text or using a custom format prevents this.
How do I keep leading zeros when pasting from another program?
Format the destination column as Text first, then paste. Alternatively, paste normally, then reformat and re-enter the values, or use a formula to pad them back to the correct width.
Can I keep leading zeros and still sort or calculate?
Yes. Use a custom number format such as 00000. The cell stores the real number for sorting and math but displays the padded version. Text-formatted values sort as text, which can produce different orderings.
Why do my zeros disappear every time I open a CSV?
Opening a CSV directly applies General formatting and converts numeric-looking fields. Import it through Data > From Text/CSV and set the column to Text, or keep the working file as .xlsx.
Does the apostrophe trick work on Mac and Excel for the web?
Yes. Typing an apostrophe before a value stores it as text in Excel for Windows, Mac, and the web. The apostrophe is not displayed in the cell.
How do I add leading zeros to a whole column of existing numbers?
Use a helper column with =TEXT(A2,"00000") or =REPT("0",5-LEN(A2))&A2, fill it down, then copy and paste the results as values over the original column if you want to replace it.