How do you sort a list of hyphenated and non-hyphenated numbers so that
2079-1 comes before 2121?
Connie Martin
How do you sort a list of hyphenated and non-hyphenated numbers so that
2079-1 comes before 2121?
Connie Martin
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
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
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
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
>
>
>
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks