+ Reply to Thread
Results 1 to 9 of 9

Sorting hyphenated numbers

  1. #1
    Registered User
    Join Date
    10-28-2017
    Location
    England
    MS-Off Ver
    Office 2016
    Posts
    8

    Sorting hyphenated numbers

    I have a long string of numbers that I need to be able to sort from highest to lowest. They are in the following format: 9-100. The first number indicates one thing, and the second another, so the sorting must take both into account.

    For example, in order:
    9-100
    9-150
    10-7
    10-35
    10-90
    11-1
    11-10

    All of the solutions I've found online are unsuitable for sorting numbers in this format. Any help please?

  2. #2
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sorting hyphenated numbers

    You can create two helper columns. If your data is in column A (starting in A1), try these:

    B1 =LEFT(A1,FIND("-",A1)-1)+0
    C1 =MID(A1,FIND("-",A1)+1,LEN(A1))+0

    Now, highlight columns A:C > Data > Sort > Add Level > Sort by Column B Then by Column C > OK

  3. #3
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sorting hyphenated numbers

    Or, using a single helper column:

    =(LEFT(A1,FIND("-",A1)-1)&RIGHT("000"&MID(A1,FIND("-",A1)+1,LEN(A1)),3))+0

  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,051

    Re: Sorting hyphenated numbers

    Brenda, just so you know, those are not really numbers, they are text looking like a number. Any tile you have any non-numerical character in a number, that number becomes text, and excel treats it as it would any "abc-type" text. What the 2 above suggestions are doing, is taking that text and converting back tio a numeric
    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

  5. #5
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sorting hyphenated numbers

    Brenda, just to be clear, the solutions provided in posts #'s 2 and 3 do not change the values in column A.

    They convert the text values in column A into numerical values in another column/s. That other column/s is then used to sort on.

    Also note that the solution in post #3 will only work when the value to the right of the dash is no more than 3 digits. Adjustments can be made if there can be numbers with more than 3 digits to the right of the dash.
    Last edited by 63falcondude; 11-03-2017 at 01:56 PM. Reason: Also note

  6. #6
    Registered User
    Join Date
    10-28-2017
    Location
    England
    MS-Off Ver
    Office 2016
    Posts
    8

    Re: Sorting hyphenated numbers

    Quote Originally Posted by 63falcondude View Post
    Brenda, just to be clear, the solutions provided in posts #'s 2 and 3 do not change the values in column A.

    They convert the text values in column A into numerical values in another column/s. That other column/s is then used to sort on.

    Also note that the solution in post #3 will only work when the value to the right of the dash is no more than 3 digits. Adjustments can be made if there can be numbers with more than 3 digits to the right of the dash.
    Thank you, that does what I need it to pretty well. There are a few cases of there being 4 digits to the right though. Does this solve it?
    =(LEFT(A1,FIND("-",A1)-1)&RIGHT("000"&MID(A1,FIND("-",A1)+1,LEN(A1)),4))+0


    Thank you also for the explanation, FDibbins.

  7. #7
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sorting hyphenated numbers

    Close. You have to include another 0 after the RIGHT function as well.

    That is:

    =(LEFT(A1,FIND("-",A1)-1)&RIGHT("0000"&MID(A1,FIND("-",A1)+1,LEN(A1)),4))+0

  8. #8
    Registered User
    Join Date
    10-28-2017
    Location
    England
    MS-Off Ver
    Office 2016
    Posts
    8

    Re: Sorting hyphenated numbers

    Thanks for your help with this problem.

  9. #9
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Sorting hyphenated numbers

    You're welcome. Thanks for the rep!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Possible to Sum a hyphenated range?
    By hazelwhisper in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-01-2017, 02:03 PM
  2. Number list to a hyphenated range
    By sprinter in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-19-2012, 12:03 PM
  3. [SOLVED] Formatting with a Hyphenated name
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-12-2012, 04:57 PM
  4. Parsing hyphenated number ranges in a field
    By pete171 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-23-2008, 07:24 AM
  5. How do I separate a hyphenated word in Excel?
    By [email protected] in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-26-2006, 08:25 AM
  6. Replies: 4
    Last Post: 11-17-2005, 10:20 AM
  7. [SOLVED] Sorting hyphenated numbers
    By Connie Martin in forum Excel General
    Replies: 5
    Last Post: 01-20-2005, 08:06 PM

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