Share via

In Excel online, how do I sort ascending with numbers & numbers with text at the end of the number?

KAREN DOMINY 0 Reputation points
2026-05-01T21:12:08.84+00:00

I want to sort like this example:

50

50x

51

51x

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

4 answers

Sort by: Most helpful
  1. Ashish Mathur 101.8K Reputation points Volunteer Moderator
    2026-05-05T22:50:49.5566667+00:00

    Enter this formula in cell A2 of sheet2

    =SORTBY(Sheet1!B3:S3475,REGEXEXTRACT(Sheet1!A3:A3475,"\d+",1))

    Hope this helps.

    User's image

    0 comments No comments

  2. Dana D 5 Reputation points
    2026-05-02T11:57:44.4633333+00:00

    [edited; option was of no interest]

    0 comments No comments

  3. Ashish Mathur 101.8K Reputation points Volunteer Moderator
    2026-05-01T23:06:08.9733333+00:00

    Hi,

    In cell B2, enter this formula

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

    Hope this helps.

    User's image


  4. Ian-Ng 12,035 Reputation points Microsoft External Staff Moderator
    2026-05-01T21:42:16.1966667+00:00

    Hi @KAREN DOMINY,

    I hope you have a good day.

    If your column contains values like 50, 50x, 51, 51x, a normal A–Z sort treats them as text and won’t reliably keep each number, and suffix grouped the way you want. A workaround in Excel for the web is to add a helper column that extracts the numeric part, then perform a multi-level (Custom) sort.

    Method A: Helper column + Custom sort (Excel for the web)

    1. Add a helper column for the number part (e.g., in B2) and fill down. Example formula (works even when there’s no “x”):
         =VALUE(LEFT(A2, FIND("x", A2&"x")-1))
      
      User's image (This extracts 50 from “50” and also 50 from “50x”.)
    2. Add a helper column for the suffix flag (e.g., in C2) and fill down. Example formula:
         =IF(RIGHT(A2,1)="x",1,0)
      
      (No suffix = 0, has “x” = 1.)
    3. Select your data range (including helper columns), then go to Data > Custom Sort and sort:
      • Sort by: the number-part column (B) > Sort Ascending
      • Then by: the suffix-flag column (C) > Sort Ascending User's image

    Tip: If sorting ever looks “off,” check whether some values are stored as numbers and others as text, mixed types can change sort behavior.

    This produces the natural order you described (like 50, 50x, 51, 51x).

    Method B: Using Helper Column in Excel application

    Step 1: Create the helper column

    • Insert a new column next to your data (let’s assume your data is in Column A, starting at A2).
    • In cell B2, enter the following formula:
    =--TEXTJOIN("", TRUE, IFERROR(MID(A2, SEQUENCE(LEN(A2)), 1) * 1, ""))
    
    • Drag this formula down.

    Step 2: Perform a multi-level sort

    • Select your entire data range (including the new helper column).
    • Go to the Data tab and select Sort.
    • In the Sort dialog, set up two levels:
      • First Level: Sort by Column B (Helper) | Smallest to Largest.
      • Second Level: Click Add Level, then sort by Column A (Original) | A to Z.
      • User's image
    • Click OK.

    I hope this helps! If the reply resolved your question, please consider marking it as the accepted answer so others with the same sorting scenario can find it more easily.


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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.