+ Reply to Thread
Results 1 to 11 of 11

Changing Sorting Order

  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    St. Petersburg
    MS-Off Ver
    Excel 2010
    Posts
    74

    Changing Sorting Order

    Hi,

    Is there a way to modify the way Excel sorts cells? This "A to Z" or "Z to A" algorithm is faulty as hell and apparently hasn't been updated since the dawn of time. It constantly sorts words in many languages in a horribly wrong order. Is it possible to create custom sorting routines?

    _____
    Also posted here.
    Last edited by Saighead; 05-13-2019 at 07:41 AM.

  2. #2
    Forum Expert avk's Avatar
    Join Date
    07-12-2007
    Location
    India
    MS-Off Ver
    Microsoft Office 2013
    Posts
    3,223

    Re: Changing Sorting Order

    Yes possible. Attach sample file with before & after required result.


    atul


    If my answer (or that of other members) has helped you, please say "Thanks" by clicking the Add Reputation button at the foot of one of their posts.

    Also: if your problem is solved, please take the time to mark your thread as SOLVED by going to the top of your first post, selecting "Thread Tools" and then "Mark thread as solved".

  3. #3
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Changing Sorting Order

    you can create a custom sorting order by creating a custom list and sorting on that - eg Monday Tuesday Wednesday ...

    Or, you can create a dummy variable in the column adjacent to the one you need to sort and use that. I use the latter all the time, but whether that suits you will depend a bit on what you're sorting and whether you can easily use formulas to get your data in the order you want.

  4. #4
    Registered User
    Join Date
    05-17-2013
    Location
    St. Petersburg
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: Changing Sorting Order

    Quote Originally Posted by avk View Post
    Yes possible. Attach sample file with before & after required result.
    Well, for example, at one point I need Excel to sort words in cells using this sorting order (Estonian alphabet): a, b, d, e, f, g, h, i, j, k, l, m, n, o, p, r, s, š, z, ž, t, u, v, õ, ä, ö, ü. Can this be done without changing locale or any other dramatic steps?

  5. #5
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Changing Sorting Order

    if you use Estonian often you could create a custom list of its alphabet and use this to create a dummy variable. Once you create it, the list will always be available – you won’t have to repeat that stage.

    to create a custom list, type each letter of the alphabet in a separate cell in successive rows in a spreadsheet. Select the range with your alphabet.


    To create a custom list run this macro:

    Please Login or Register  to view this content.
    Or follow the instructions here:
    HTML Code: 

    To create the dummy variable, add a blank column next to the one you want to sort and enter this formula:
    =LOWER(LEFT(A1,1))
    (assuming A1 is the first cell with sort data – adjust accordingly)

    Copy this down the column next to every cell with a value you want to sort.

    Select both the column to sort and the column with the dummy variable.

    Select data > sort and under ‘order’ select ‘custom list’ then pick your alphabet from the custom lists available

    Under ‘Sort by’, select the column with the dummy variable first, then select ‘add level’ and add the primary sort list.

    basically what this does is to take the first letter of your entries ans sort it in the order of the Estonian alphabet you provided, then sorts by the whole word to order the rest of the list.

  6. #6
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Changing Sorting Order

    ah - I have just realised this will sort on the first letter of each word but it may not be properly alphabetical as subsequent letters will be sorted on the roman alphabet

    there is a discussion of the issue here:
    https://answers.microsoft.com/en-us/...8-d2f9fe3c2c33

    I'm shutting down now but will give it some thought and try to get back to you if no-one comes up with a better solution.

  7. #7
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Changing Sorting Order

    ok I think I have worked out how to do this with a macro, though it may be slow if you have a large list.
    it sorts the selected text - single column only, in the order that the characters appear in the MyAlph array (I uysed the order that you gave above).
    basically what it does is

    1. insert a new column to the right of the selected text and copies the text there
    2. in the new column, replaces the characters in the array with strings made up of numbers indicating the character's position in the array
    3. sorts the text and numbers on the numbers column
    4. deletes the numbers column

    Let me know if it works

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-17-2013
    Location
    St. Petersburg
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: Changing Sorting Order

    @NickyC

    Thank you for the effort. But...
    — "š, ž, õ, ä, ö, ü" are high-ASCII or Unicode characters. Whichever they are, VBA in Office 2010 converts them to whatever corresponds to them in the current Windows codepage or something. In my case, they are converted into Cyrillic characters (which is really weird, come to think of it, since both my Windows and my MS Office Suite are non-localized). As a result, the sorting order goes completely out of whack...
    — the script sorts one column only, which would wreak havoc in my files since there's LOTS of related columns...

    PS. I was hoping (in retrospect, somewhat too optimistically) that Excel had a "civilized" solution to the problem. Without generating so much garbage, without helper columns and elaborate replacement schemes. Without all that "dance with a tambourine" as they say in my language. But sadly, even after more than 3 decades on the market Excel still is a piece of junk in so many respects that it's just depressing...

  9. #9
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Changing Sorting Order

    Hi Saighead

    I don't think Excel is going to deliver what you want, at least not simply.

    the macro could be adapted to sort more than one column, but I'd need to know which column contains the sort key. it also won't do a sort on more than one key. And I can't think of a way to do it without the "dance with a tambourine' I'm afraid.
    I'm rather a bumbling amateur on these forums and it may be than someone with more expertise can help.

    Let me know if you'd like to try an amended macro. I'm logging off now, but could look at it tomorrow

  10. #10
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Changing Sorting Order

    Hi

    this variation should allow you to sort several columns at once. If you select multiple columns it will show an input box asking which column you want to sort on. Enter eg A to sort on column A

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    05-17-2013
    Location
    St. Petersburg
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: Changing Sorting Order

    @NickyC

    Thanks a lot! With just a bit of tweaking to make VBA see non-ASCII characters correctly the script works great.

+ 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. Changing default sorting order of pivot tables
    By Kabouterke in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 10-29-2015, 05:38 AM
  2. Replies: 4
    Last Post: 03-17-2015, 04:36 AM
  3. Changing the Tab Order using VBA
    By 24t42 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-17-2013, 01:43 PM
  4. Change order of Legend without changing the order of the chart
    By Grimace in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 11-22-2012, 11:53 AM
  5. sorting rows without changing order of my values!
    By roger in forum Excel General
    Replies: 1
    Last Post: 03-03-2006, 08:30 AM
  6. sorting in order
    By ceemo in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 09-06-2005, 12:05 PM
  7. sorting in order
    By ceemo in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-30-2005, 08:20 AM

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