Several months ago I re-published my Code for an **Enhanced Insertion Sort Algorithm**.

At that point, my colleague SNB wrote to tell me about other methods that could be applied to achieve the same results.

SNB is the owner of a very valuable Web Site: **VBA for Smarties**

http://www.snb-vba.eu/

In particular, check out his great tutorial on VBA Arrays

http://www.snb-vba.eu/VBA_Arrays_en.html

He evaluated my code and provided a much simpler solution using

**VBA-ADO Library which has a sorting method**.

I am republishing the improved VBA project to provide a hands-on demonstration that presents the hard way and the easy way to sort using VBA.

SNB’s code is very efficient and direct, one routine for sorting numerical values and another one for sorting string. Each routine has 30 lines of code!

My code, on the other hand, has two routines for sorting numerical values and two routines for sorting strings along with a number of supporting routines. All in all, my codes require nearly 900 lines of code.

I have included a tab in the Workbook to demonstrate that our results match the stable sorting that is provided by the Worksheet sorting.

I want to point out that our sorting procedures are stable. Meaning that as the sorting is progressing through the original data, that the position of each new data item that is added to the sorted collection maintains its relative position to where it was in the original data.

I also want to underscore the importance that I give generating a permutation array to act as a sorting operator.

Based on what I have learned from SNB, I will be using his code as I continue the development of my Tool Kit of Numerical Techniques.

**Link to the Workbook**:

https://drive.google.com/open?id=0BxNZW5nboqyIaHlJdW9jQTF5d28

**Other important references:**

**Stable Sorting:**

https://stackoverflow.com/questions/1517793/what-is-stability-in-sorting-algorithms-and-why-is-it-important

https://en.wikipedia.org/wiki/Sorting_algorithm#Stability

http://homepages.math.uic.edu/~leon/cs-mcs401-s08/handouts/stability.pdf

**Insertion Sorting:**

https://en.wikipedia.org/wiki/Insertion_sort

http://www.geeksforgeeks.org/insertion-sort/

https://www.tutorialspoint.com/data_structures_algorithms/insertion_sort_algorithm.htm

**Permutations for Sorting:**

https://rosettacode.org/wiki/Sorting_algorithms/Permutation_sort

http://www.nik.no/2008/06-Maus.pdf

http://pages.cs.wisc.edu/~fischer/cs538.s08/lectures/Lecture35.4up.pdf

**Other Links to VBA for Smarties:**

http://www.snb-vba.eu/VBA_Dictionary_en.html

http://www.snb-vba.eu/VBA_Collection_en.html

### Like this:

Like Loading...