+ Reply to Thread
Results 1 to 4 of 4

Sorting Text That Contains Numbers

  1. #1
    Registered User
    Join Date
    12-27-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    2

    Sorting Text That Contains Numbers

    I am attempting to sort a list of movies by their title. I'm having trouble properly sorting those that contain leading numbers. This is what I'm getting:

    12 Angry Men
    12 Monkeys
    2 Days in Paris
    2011: A Space Odyssey
    25th Hour
    28 Days Later
    300
    40 Year Old Virgin

    What I want is:

    2 Days in Paris
    12 Angry Men
    12 Monkeys
    25th Hour
    28 Days Later
    40 Year Old Virgin
    300
    2011: A Space Odyssey

    It appears to be sorting by the first digit only and ignoring the rest. When sorting letters, it reads every consecutive letter, which is the proper way to alphabetize. How do I get it to do the same with digits?

    Thanks in advance.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: Sorting Text That Contains Numbers

    Hi BadAdjective and welcome to the forum

    Some1 will probably have a more eligant solution, but try this. Assuming your data is in column A, add a helper column in B and use this, copied down...
    =LOOKUP(99^99,--("0"&MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),ROW($1:$10000)))).....Courtesy of:*Ron Coderre
    this will extract the leading numbers.

    then sort based 1st on B, and then 2nd on A
    Last edited by FDibbins; 12-27-2012 at 09:13 PM.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    12-27-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Sorting Text That Contains Numbers

    Thanks for the formula, however I do need a more simple way of doing this, if one exists. Is there any way to format the cells themselves to achieve this and avoid using formulas or additional columns?

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: Sorting Text That Contains Numbers

    formatting just changes the cosmetics of a cell, it has no affect on the actual cell contents

    The helper column can be "hidden" by changing the color to white on white
    Last edited by FDibbins; 12-27-2012 at 09:51 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1