Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected order for a range sorted with non alpha-numeric characters

Tags:

I'm getting an unexpected result when I sort a list with Excel or with some VBA (Range.Sort). It seems that the hyphen is simply ignored when the text is sorted:

List sorted with Excel

align-content
align-items
alignment-baseline    << Should be after "align-self"
align-self
animation-delay

The same list sorted with Libre Office

align-content
align-items
align-self
alignment-baseline
animation-delay

The documentation doesn't provide any information on this behavior:

https://support.office.com/en-gb/article/Sort-data-in-a-range-or-table-62d0b95d-2a90-4610-a6ae-2e545c4a4654?ui=en-US&rs=en-GB&ad=GB#__toc246836970

https://msdn.microsoft.com/en-us/library/office/ff840646.aspx

So is there any rule behind this behavior ?

Is there an option to sort the list the same way a human would do (as Libre Office does) ?

like image 936
michael Avatar asked Oct 07 '16 16:10

michael


People also ask

What is alphanumeric sorting?

Sorting alpha numeric strings Any alpha numeric sort places the alpha in order, and then numbers in order by their first numeral, so 1300 will come before 140 which does not work well for lists like call numbers in libraries.

What is the correct sorting function to list colors in alphabetical order?

Sort by cell color, font color, or icon Select a cell in the column you want to sort. On the Data tab, in the Sort & Filter group, click Sort. In the Sort dialog box, under Column, in the Sort by box, select the column that you want to sort. Under Sort On, select Cell Color, Font Color, or Cell Icon.

Why does excel sort 1 and 10?

The reason this happens is because Excel has decided that the 'numbers' are actually text and so it is sorting the 'text'. So in much the same way that words sort based on there letters, the numbers sort on the digits instead of the value.


1 Answers

Excel ignores hyphens in doing the sort, unless that is the only difference between two words.

One work around is to create a "helper column", replacing the hyphen (code 45) with a dot (code 46). Sort on the helper column

=SUBSTITUTE(A1,"-",".")

I have read someplace that the default sort order has a sequence:

  • apostrophe
  • hyphen
  • space

with the first two generally ignored

That being the case, replacing the hyphen with a space might be more logical.

like image 152
Ron Rosenfeld Avatar answered Sep 22 '22 16:09

Ron Rosenfeld