Further Examples using the routines from the previous post
The sorted array is displayed in the spreadsheet along side the original range used as test data for the inputted array. ( The yellow highlighted range is that produced by the array sort routine, Sub SimpleArraySort() , and the green highlighted range is that produced by the VBA Range.Sort method routine, Sub Range_Sort()
_____ ( Using Excel 2007 32 bit )
Worksheet: Sorting
Row\Col A B C D E F G 1 2c WasB2 32WasB8 6WasB7 3AB WasB3 6WasB7 32WasB8 4Aa WasB4 A WasB5 A WasB5 5A WasB5 Aa WasB4 Aa WasB4 6C WasB6 AB WasB3 AB WasB3 7 6WasB7 bcde WasB9 bcde WasB9 8 32WasB8 C WasB6 c WasB2 9bcde WasB9 c WasB2 C WasB6 10
To reverse this to descending so that things “get smaller as you go down the rows”, you simply need to change
the > to a < in the array routine
and
the Order1:=xlAscending to Order1:=xlDescending in the VBA Range.Sort routine
_____ ( Using Excel 2007 32 bit )
Worksheet: Sorting
Row\Col A B C D E F G 1 2c WasB2 c WasB2 c WasB2 3AB WasB3 C WasB6 C WasB6 4Aa WasB4 bcde WasB9 bcde WasB9 5A WasB5 AB WasB3 AB WasB3 6C WasB6 Aa WasB4 Aa WasB4 7 6WasB7 A WasB5 A WasB5 8 32WasB8 6WasB7 32WasB8 9bcde WasB9 32WasB8 6WasB7 10
I intended developing the solution into a function, so as a start to this, the routine will be modified to take an Optional argument of 0 or 1 , with the default of 0 being the case for an Ascending list. I am not being particularly efficient with the coding, and will duplicate sections.
A full routine is posted in the next post




Reply With Quote
Bookmarks