Sort List Alphabetically

Get help with using AutoHotkey and its commands and hotkeys
AHKd00b
Posts: 10
Joined: 16 May 2018, 16:12

Sort List Alphabetically

16 May 2018, 16:17

Hello there, I've created a script that uses COM to cycle through previous/next values on an Excel column AutoFilter. I've gotten it to work quite well except for the part that sorts the values from the selected column before storing them into an array. The way that Excel sorts its row values is not the same as a regular Alphabetical sorting. Please see example codes:

Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus


As you can see the sort order does not match how Excel sorts. The sort order in my script needs to be identical to Excel's sort method so when the list is inserted into an Array, the index value of each row should match with Excel so I can accurately call each value by using its index.

Any ideas on how to solve this? Perhaps someone has a sort function that already does this? Thanks!
wolf_II
Posts: 1975
Joined: 08 Feb 2015, 20:55

Re: Sort List Alphabetically

16 May 2018, 16:40

Try this:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

I hope that helps.
AHKd00b
Posts: 10
Joined: 16 May 2018, 16:12

Re: Sort List Alphabetically

16 May 2018, 17:10

WOW!!

That was so simple! Thanks for adding the comments, it makes total sense now on how Excel does its sorting.

You sir are a genius!!!! I love this forum :)

If anyone is interested in a Filter On Previous/Next Value script for Excel let me know! Works great for huge spreadsheets where you just want to cycle down a single column.

Thanks again!!
User avatar
jeeswg
Posts: 4760
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Sort List Alphabetically

16 May 2018, 17:13

I wrote this to handle Excel sorts. It's possible that there are other issues. Also, what if one of the strings already contains ':', you'd need a temporary unused character e.g. Chr(1) is often a good candidate.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

AHKd00b
Posts: 10
Joined: 16 May 2018, 16:12

Re: Sort List Alphabetically

16 May 2018, 17:26

Thank you jeeswg!

I have tried your code and it works great as well. I have saved both examples for later use :)
AHKd00b
Posts: 10
Joined: 16 May 2018, 16:12

Re: Sort List Alphabetically

16 May 2018, 17:41

Turns out there's an even easier method :dance: :thumbup:

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

Sort, list, CL
wolf_II
Posts: 1975
Joined: 08 Feb 2015, 20:55

Re: Sort List Alphabetically

16 May 2018, 17:49

:bravo: thx for sharing :D
User avatar
jeeswg
Posts: 4760
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Sort List Alphabetically

16 May 2018, 19:00

I have posted some important Excel sort information here:
Excel: sort order - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=43426

How to correctly sort alphanumeric data in Excel
https://support.microsoft.com/en-gb/help/322067/how-to-correctly-sort-alphanumeric-data-in-excel
Excel sorts data in the following order:

0 1 2 3 4 5 6 7 8 9 (space) ! " # $ % & ( ) * , . / : ; ? @ [ \ ] ^ _ ` { | } ~ + < = > A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Apostrophes (') and hyphens (-) are ignored, with one exception: If two text strings are the same except for a hyphen, the text with the hyphen is sorted last.

- It seems that the website has changed and no longer displays that information, luckily I was able to retrieve it via Bing's cache.

Return to “Ask For Help”

Who is online

Users browsing this forum: Mimir and 55 guests