Formatting Issues

How to Sort Excel Text by Leading Digits and Suffixes

Camila MilosovichCamila Milosovich Nov 10, 2026 869 views

Question details

The user wants to sort alphanumeric values in Excel based on their leading numeric digits.

How to Sort Excel Text by Leading Digits and Suffixes
Product
Microsoft Excel
Device & OS
not provided
Scenario
Sorting a column containing a mix of numbers with leading zeros (e.g., 0031, 0033) and alphanumeric strings (e.g., 0031A, 0033A).
Observed behavior
Excel sorts the data incorrectly because it treats some entries as numerical values and others as text strings, breaking the desired logical order.
Before you start

Identify whether your data has a consistent number of leading digits, as this will determine which formula or formatting method works best for your dataset.

Solution 1Recommended

Format Data as Text Before Entry

The simplest way to prevent mixed sorting issues is to ensure Excel treats all entries uniformly as text from the start.

When Excel mixes text strings and pure numbers, sorting behavior becomes unpredictable. By forcing all cells to be recognized as text, Excel applies alphabetical sorting rules uniformly, keeping leading zeros intact and maintaining logical sequence.

1
Select the target column

Highlight the entire column where you plan to enter the alphanumeric values.

2
Change format to Text

Right-click the selection and choose 'Format Cells', or go to the Home tab and find the Number Format dropdown. Select 'Text' from the list of formats and click OK.

3
Use apostrophe prefix

Alternatively, type an apostrophe (') before the number when entering data manually (e.g., '0031) to force Excel to store the value as text.

Format Data as Text Before Entry
Consistent Sorting: Formatting as text prevents Excel from dropping leading zeros and ensures alphanumeric suffixes sort correctly directly after their root numbers.
Efficient Data Sorting

Sort Complex Alphanumeric Data Easily in WPS Office

WPS Spreadsheet provides powerful data processing capabilities, including advanced sorting options and full support for dynamic array formulas like SORTBY. Manage your complex datasets efficiently and resolve mixed text formatting issues with ease.

  1. 1. Open your workbook: Launch WPS Spreadsheet and open the file containing your mixed alphanumeric entries.
  2. 2. Select the data range: Highlight the specific cells or column you wish to sort.
  3. 3. Access Custom Sort: Go to the 'Data' tab and click on 'Sort' to access custom sorting options, or format the cells as text directly from the Home tab.
  4. 4. Use dynamic array formulas: Alternatively, type the =SORTBY() formula directly into an empty cell to automatically generate a sorted list, just as you would in Excel.
Fully compatible with Microsoft Excel formulas and formatting.Advanced Sort dialog to handle mixed text and numbers.Lightweight and completely free to use.Familiar, easy-to-navigate user interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Excel sort 0031 after 0031A?

Excel automatically removes leading zeros from numbers and treats them as purely numeric values (e.g., 31), while treating 0031A as a text string. Because Excel often sorts numbers differently than text, the logical alphanumeric sequence is broken.

How do I sort numbers and text together without using formulas?

You can use the 'Text to Columns' feature under the Data tab to split the numeric and alphabetical parts into separate columns. Sort the data by the numeric column first, and then optionally recombine them later.

What does the double dash (--) do in the SORTBY formula?

The double unary operator (--) converts the text string extracted by the LEFT function back into a true numeric value. This ensures the SORTBY function sorts the array numerically based on value rather than alphabetically.