How to Sort Alphanumeric Values in Excel with a Custom Order
Question details
The user needs to sort mixed numeric and text references by their leading digits to achieve a specific custom order.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Organizing a dataset containing alphanumeric strings like 001, 01, 0130, 11, 289B, and 298BCFG where the numerical prefix dictates the row order.
- Observed behavior
- Standard A-Z or Z-A sorting treats the entire string as text, which fails to reproduce the correct numerical sequence for the leading digits.
Review your dataset to identify the consistent pattern of your alphanumeric strings (e.g., leading numbers followed by text), as this pattern dictates whether a helper formula or a VBA script is required.
Use a VBA Macro for Custom Alphanumeric Sorting
Implement a VBA procedure to automatically parse leading numbers from trailing letters and sort the dataset accordingly.
When standard sorting fails on mixed alphanumeric strings, VBA (Visual Basic for Applications) provides the most robust method to separate the numeric values from text dynamically.
This approach creates a custom function that evaluates the numerical weight of the string, ensuring that numbers like '289' are correctly sequenced before '298', regardless of the trailing letters.
Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications window.
Click on 'Insert' in the top menu and select 'Module' to create a blank workspace for your script.
Input a VBA script designed to extract leading numbers (e.g., using a Regular Expression or a character loop) and assign it as a User-Defined Function.
Close the VBA editor, use your newly created function in an adjacent column to extract the numeric values, and then use the standard 'Data' > 'Sort' tool to sequence your rows based on this new column.

Extract Leading Digits Using Helper Columns
Create an adjacent column using text manipulation formulas to isolate the leading numbers for standard sorting.
Sort Alphanumeric Data Seamlessly in WPS Spreadsheet
WPS Spreadsheet provides powerful data handling capabilities, fully supporting complex formulas and VBA macros to help you effortlessly separate and sort mixed alphanumeric values.
- 1. Open Your File: Launch WPS Spreadsheet and open the document containing your alphanumeric data.
- 2. Set Up a Helper Column: Insert a new column beside your target data to serve as the sorting key.
- 3. Extract the Numeric Value: Use Flash Fill (Ctrl + E) or a text formula to pull the leading digits from the alphanumeric strings into the helper column.
- 4. Sort the Dataset: Highlight your data range, go to the 'Data' tab, click 'Sort', and choose the helper column to order your items accurately.

Frequently Asked Questions
Why does Excel sort 11 before 2 in alphanumeric data?
When a cell contains both text and numbers, Excel treats the entire cell value as a text string. Text sorting evaluates characters from left to right, meaning the character '1' in '11' is sequenced before the character '2', regardless of the mathematical value.
Can I sort alphanumeric data without using VBA macros?
Yes, you can avoid VBA by using a helper column. By applying text manipulation formulas (like LEFT, FIND, or VALUE) or using the Flash Fill feature, you can extract the leading numbers into the helper column and sort your dataset based on those extracted numbers.
How do I ignore trailing letters when sorting?
To ignore trailing letters, you must separate the leading numbers from the letters. Create a new column and extract just the numeric prefix. Once the numbers are isolated in their own column, apply a standard numerical sort to that column while keeping your original rows intact.




