Sort on a text field

Mary Eleanor Whelan 20 Reputation points
2026-06-25T22:22:40.9933333+00:00

How to sort an excel file with location field of 1, 2A,, 3B, 20A, and 30B and not 1, 2A, 20A, 3B and 30B?

Microsoft 365 and Office | Excel | For home | Windows
0 comments No comments

Answer accepted by question author
EmilyS726 268.6K Reputation points Independent Advisor
2026-06-25T23:01:14.61+00:00

Hello

I am afraid there's no direct way to sort it like that. It will require helper columns to achieve this result.

Assuming your data lives on A column, say A2 cell with A1 being the header.

Then on B2 cell, put in this formula:

=VALUE(LEFT(A2,IF(ISNUMBER(--RIGHT(A2,1)),LEN(A2),LEN(A2)-1)))

Then on C2 cell, put in this formula:

=IF(ISNUMBER(--RIGHT(A2,1)),"",RIGHT(A2,1))

Then you can sort B column from smallest to biggest number, and it should then sort A column with the result you want. see screenshot for example:

User's image

Was this answer helpful?

2 people found this answer helpful.

3 additional answers

Sort by: Newest
  1. Ashish Mathur 102.4K Reputation points Volunteer Moderator
    2026-06-26T23:16:27.0633333+00:00

    Hi,

    Enter this formula in cell B2

    =SORTBY(A2:A6,1*REGEXEXTRACT(A2:A6,"\d+"))

    Hope this helps.

    User's image

    Was this answer helpful?

    0 comments No comments

  2. IlirU 2,651 Reputation points Volunteer Moderator
    2026-06-26T07:16:49.9666667+00:00

    User's image

    Hi @Mary Eleanor Whelan

    There is no need for a helper column. There is also no need for multiple formulas, as you can get the desired result with just one formula. See the screenshot and apply the formula below.

    =SORTBY(A2:A6, TEXT(SORT(--REGEXEXTRACT(A2:A6, "\d+")), "@"))
    

    IlirU

    Was this answer helpful?

    1 person found this answer helpful.

  3. Mary Eleanor Whelan 20 Reputation points
    2026-06-25T23:19:14.5933333+00:00

    Thank you for your suggestion. I had a friend suggest this.. to add a column H with this formula

    =VALUE(TEXTBEFORE(G2,{"A","B"},,1,,G2))

    where my 2A or 30B was in column G. I dragged the formula down the column H to copy it. It changed the sort order of column G.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.