Preserve Leading Zeros and Sort Item Numbers in Excel
Question details
Preserve leading zeros in item numbers and sort the values consistently in Excel.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Item numbers have varying lengths and are entered, pasted, or imported into a worksheet.
- Observed behavior
- Excel removes leading zeros from numeric values, custom formats can add unwanted zeros, and inconsistently stored values may not sort as expected.
Check whether the original item numbers still contain their leading zeros and decide whether you need text order or numeric order. Formatting existing numbers as text cannot recover zeros that Excel has already removed.
Store item numbers as text before entering or importing them
Use this method to preserve each code exactly as supplied and sort the column consistently as text.
Select the item-number column, then choose Home > Number Format > Text before entering the codes.
Type the codes into the formatted column. For a text file, use Data > From Text/CSV, choose Transform Data, and set the item-number column's data type to Text before loading. If an automatic Changed Type step has already converted the codes to numbers, remove that step first.
If pasting from another source, use Home > Paste > Paste Special and choose a text option if available. Check that values such as 058 still display their original zeros; copying a numeric value cannot restore zeros already lost.
Select the item-number column and choose Data > Sort A to Z. If Excel asks how to handle numbers stored as text, choose the option to sort numbers and numbers stored as text separately.

Sort item numbers by numeric value with a helper column
Use a helper column when codes have different lengths but need to appear in numeric order while retaining their original text.
Preserve and Sort Item Numbers in WPS Spreadsheets
Use WPS Spreadsheets to format item-number cells as text before entering codes, then sort the codes as text or use a helper column for numeric order.
- 1. Open your spreadsheet: Open the workbook in WPS Spreadsheets and select the destination column for the item numbers.
- 2. Set the column to Text: On the Home tab, open the number format list and select Text before entering the codes.
- 3. Enter and check the codes: Type the original item numbers into the formatted column and verify that codes such as 058 retain their leading zeros.
- 4. Choose a sort order: Select the data and use Data > Sort to sort the item-number column as text. For numeric order, create a helper column with =VALUE(A2), fill it down, and sort the full range by that column.

Frequently Asked Questions
Can I restore leading zeros after Excel removes them?
Changing the cell format to Text will not restore lost zeros. Re-enter or reimport the original codes as text. If every code has a known fixed length, a formula or custom format may help, but it cannot determine the original lengths of variable-length codes.
Why does 10 sort before 2 when item numbers are text?
Text sorting compares characters from left to right. To sort by numeric value instead, create a helper column with =VALUE(A2) and use Data > Sort on the helper column.
Should I use a custom number format for item numbers?
A custom format such as 000 can display fixed-width numbers with leading zeros, but it does not preserve the zeros as part of the stored value. For codes with varying lengths, storing the original values as text is usually more suitable.
Why did my imported codes lose their zeros even though I selected Text?
An earlier import step may have converted the column to numbers. In the Power Query editor, check Applied Steps and remove an automatic Changed Type step before setting the item-number column to Text and loading the data.




