Fix Incorrect Sorting of Alphanumeric Codes in Excel
Question details
The user needs alphanumeric codes to sort in their intended numeric order in Excel.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Sorting a column containing text codes with a shared prefix and numeric portions, such as GTS-07, GTS-036A, and GTS-111.
- Observed behavior
- Excel compares the values as text strings, so numeric portions with different digit lengths can appear in an unexpected order.
Check the longest numeric portion used in the code column so every code can use the same number of digits. Keep any letter suffixes, such as A in GTS-036A, after the zero-padded number.
Add leading zeros to the numeric portion before sorting
Use this method when your codes have a consistent prefix and the numeric portion can be formatted to a fixed width.
Excel sorts text character by character. Making every numeric portion the same length causes the text order to match the intended numeric order.
Review the code column and identify the largest numeric value. For example, if values can reach 999, use a three-digit numeric portion.
Click each code cell in the Excel column and add leading zeros to the numeric portion. Change GTS-07 to GTS-007, GTS-25 to GTS-025, and keep suffixes after the number, such as GTS-036A.
Select any cell in the code column, then go to Data > Sort A to Z. If Excel prompts you, choose Expand the selection to keep related row data together.

Create a standardized code column for future imports
Use this approach when imported codes repeatedly have inconsistent numeric widths and you want to preserve the original values.
Standardize and Sort Alphanumeric Codes in WPS Spreadsheet
WPS Spreadsheet lets you edit code values and sort the full table by a standardized, zero-padded code column. This makes entries such as GTS-007 and GTS-111 follow the intended numeric sequence while keeping associated row data aligned.
- 1. Open the workbook in WPS Spreadsheet: Launch WPS Office, select Spreadsheets, and open the Excel workbook containing the code column.
- 2. Standardize the numeric width: Select the code cells and update varying numeric portions to a fixed width, such as changing GTS-07 to GTS-007.
- 3. Select the data range: Click a cell in the table, or drag to select the complete table so related columns remain together during sorting.
- 4. Sort the codes: Go to Data > Sort, select the standardized code column, choose Ascending, and confirm the sort.

Frequently Asked Questions
Why does Excel place GTS-111 before GTS-25?
The cells are text values, so Excel compares characters from left to right. After the shared GTS- prefix, the character 1 in 111 sorts before the character 2 in 25. Change GTS-25 to GTS-025 to use equal-width numeric portions.
How many leading zeros should I add to my Excel codes?
Use enough digits for the largest number in the series. Use three digits for values up to 999, four digits for values up to 9999, and apply that width consistently to every code.
Will adding zeros affect a suffix such as GTS-36A?
Keep the suffix after the padded number. For a three-digit format, change GTS-36A to GTS-036A so the letter remains attached to the correct numeric code.
Can I keep the original code values and still sort correctly?
Yes. Insert a helper column beside the original codes, enter standardized zero-padded versions there, and use Data > Sort to sort the table by the helper column.




