+ Reply to Thread
Results 1 to 6 of 6

Sorting hyphenated numbers

Hybrid View

  1. #1
    Connie Martin
    Guest

    Sorting hyphenated numbers

    How do you sort a list of hyphenated and non-hyphenated numbers so that
    2079-1 comes before 2121?

    Connie Martin

  2. #2
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545
    IMHO, you will need to ensure all entries are text (as hyphenated numbers will be treated as text). You will then need to separate the hyphened number away from the base number (use Text to Columns with the ' - ' as the delimiter). This will give you two columns of numbers, base numbers in one, hyphened in the next. Sort your range using the now base numbers only column as the Sort By column.

    So, assuming your list of numbers is in column D, insert columns E-F. Text to Columns into E & F, sort with E as your Sort-By column (add any additional columns related to this data). Then Delete columns E & F

    HTH
    Bruce
    The older I get, the better I used to be.
    USA

  3. #3
    Max
    Guest

    Re: Sorting hyphenated numbers

    Try sorting the list on an adjacent helper col

    Assuming the list is in col A, A1 down

    Put in B1: =TEXT(A1,"@")
    Copy down

    Then sort both cols A and B by col B > Ascending

    This should return the results ..
    --
    Rgds
    Max
    xl 97
    ---
    GMT+8, 1° 22' N 103° 45' E
    xdemechanik <at>yahoo<dot>com
    ----
    "Connie Martin" <[email protected]> wrote in message
    news:[email protected]...
    > How do you sort a list of hyphenated and non-hyphenated numbers so that
    > 2079-1 comes before 2121?
    >
    > Connie Martin




  4. #4
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545
    Max: your formula does make sure all is text, however, Excel sorts text in alpha order, and entries without a hyphen will *always* come before text with a hyphen.

    To meet the request of the poster, removing the '-' and trailing characters is (to the best of my knowledge) imperative.

    e.g.: (all as text)

    2121
    1234-0
    2079-1
    12-340
    1-2340
    123-40
    9854

    will Sort>Ascending as:

    2121
    9854
    1-2340
    12-340
    123-40
    1234-0
    2079-1

    My method, Text to Columns gives:

    2121 2121
    9854 9854
    1-2340 1 2340
    12-340 12 340
    123-40 123 40
    1234-0 1234 0
    2079-1 2079 1

    After sorting by second column:

    1-2340 1 2340
    12-340 12 340
    123-40 123 40
    1234-0 1234 0
    2079-1 2079 1
    2121 2121
    9854 9854

    Deleting the 'helper' columns leaves data in desired order (i.e. 2079-1 is before 2121).

    HTH

  5. #5
    Connie Martin
    Guest

    Re: Sorting hyphenated numbers

    Thank you. That works. I put the column outside the print area. I was
    hoping there would be a list one could create and then sort by it, but I
    guess not.

    Thanks again
    Connie Martin

    "Max" wrote:

    > Try sorting the list on an adjacent helper col
    >
    > Assuming the list is in col A, A1 down
    >
    > Put in B1: =TEXT(A1,"@")
    > Copy down
    >
    > Then sort both cols A and B by col B > Ascending
    >
    > This should return the results ..
    > --
    > Rgds
    > Max
    > xl 97
    > ---
    > GMT+8, 1° 22' N 103° 45' E
    > xdemechanik <at>yahoo<dot>com
    > ----
    > "Connie Martin" <[email protected]> wrote in message
    > news:[email protected]...
    > > How do you sort a list of hyphenated and non-hyphenated numbers so that
    > > 2079-1 comes before 2121?
    > >
    > > Connie Martin

    >
    >
    >


  6. #6
    Max
    Guest

    Re: Sorting hyphenated numbers

    You're welcome !
    Thanks for posting back
    --
    Rgds
    Max
    xl 97
    ---
    GMT+8, 1° 22' N 103° 45' E
    xdemechanik <at>yahoo<dot>com
    ----
    "Connie Martin" <[email protected]> wrote in message
    news:[email protected]...
    > Thank you. That works. I put the column outside the print area. I was
    > hoping there would be a list one could create and then sort by it, but I
    > guess not.
    >
    > Thanks again
    > Connie Martin




+ 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