I'm looking for a decent sort implementation for arrays in VBA. A Quicksort would be preferred. Or any other sort algorithm other than bubble or merge would suffice.
Please note that this is to work with MS Project 2003, so should avoid any of the Excel native functions and anything .net related.
This is what I use to sort in memory - it can easily be expanded to sort an array.
Explanation in German but the code is a well-tested in-place implementation:
Invoked like this:
I converted the 'fast quick sort' algorithm to VBA, if anyone else wants it.
I have it optimized to run on an array of Int/Longs but it should be simple to convert it to one that works on arbitrary comparable elements.
Natural Number (Strings) Quick Sort
Just to pile onto the topic. Normally, if you sort strings with numbers you'll get something like this:
But you really want it to recognize the numerical values and be sorted like
Here's how to do it...
Note:
Natural Number Quick Sort
Natural Number Compare(Used in Quick Sort)
isDigit(Used in CompareNaturalNum)
I wonder what would you say about this array sorting code. It's quick for implementation and does the job ... haven't tested for large arrays yet. It works for one-dimensional arrays, for multidimensional additional values re-location matrix would need to be build (with one less dimension that the initial array).