Data Import & Export

Preserve Leading Zeros and Sort Item Numbers in Excel

Rana GarciaRana Garcia Nov 27, 2026 869 views

Question details

Preserve leading zeros in item numbers and sort the values consistently in Excel.

Preserve Leading Zeros and Sort Item Numbers 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.
Before you start

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.

Solution 1Recommended

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.

1
Format the destination column

Select the item-number column, then choose Home > Number Format > Text before entering the codes.

2
Enter or import 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.

3
Check pasted values

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.

4
Sort the item numbers

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.

Store item numbers as text before entering or importing them
Text order differs from numeric order: Text sorting compares characters, so codes such as 10 and 2 may not appear in numeric order. Use a helper column if numeric order is required.
Work with item numbers in WPS

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. 1. Open your spreadsheet: Open the workbook in WPS Spreadsheets and select the destination column for the item numbers.
  2. 2. Set the column to Text: On the Home tab, open the number format list and select Text before entering the codes.
  3. 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. 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.
Preserve leading zeros in item numbers entered as textSort codes as text or by a numeric helper columnOpen and save Microsoft Excel XLSX filesWork in a familiar spreadsheet interface
microsoft office alternative - wps office

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.