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 SimpleArraySort3() , and the green highlighted range is that produced by the VBA Range.Sort method routine, Sub Range_Sort()
Ascending Order
Code:Sub TestieSimpleArraySort3() Call SimpleArraySort3(0) End Sub '_____ ( Using Excel 2007 32 bit )Code:Sub Range_Sort() Rem 0 test data, worksheets info Dim WsS As Worksheet: Set WsS = ThisWorkbook.Worksheets("Sorting") Dim RngToSort As range: Set RngToSort = WsS.range("A2:B9") ' alternative: ' Set RngToSort = Selection ' ' Selection.JPG : https://imgur.com/HnCdBt8 Rem 1 For demo purposes we will sort a copy of the range RngToSort.Offset(0, RngToSort.Columns.Count * 2).Clear ' WsS.Columns("E:F").Clear ' CHANGE TO SUIT RngToSort.Copy Destination:=RngToSort.Offset(0, RngToSort.Columns.Count * 2) Dim RngCopy As range: Set RngCopy = RngToSort.Offset(0, RngToSort.Columns.Count * 2) RngCopy.Sort Key1:=RngCopy.Columns("A:A"), Order1:=xlAscending, MatchCase:=False 'RngCopy.Sort Key1:=RngCopy.Columns("A:A"), Order1:=xlDescending, MatchCase:=False Let RngCopy.Interior.Color = vbGreen End Sub
Worksheet: Sorting
Row\Col A B C D E F G 1 2c WasB2 6WasB7 6WasB7 3AB WasB3 32WasB8 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
Descending Order
Code:Sub TestieSimpleArraySort3() Call SimpleArraySort3(2246) End Sub '_____ ( Using Excel 2007 32 bit )Code:Sub Range_Sort() Rem 0 test data, worksheets info Dim WsS As Worksheet: Set WsS = ThisWorkbook.Worksheets("Sorting") Dim RngToSort As range: Set RngToSort = WsS.range("A2:B9") ' alternative: ' Set RngToSort = Selection ' ' Selection.JPG : https://imgur.com/HnCdBt8 Rem 1 For demo purposes we will sort a copy of the range RngToSort.Offset(0, RngToSort.Columns.Count * 2).Clear ' WsS.Columns("E:F").Clear ' CHANGE TO SUIT RngToSort.Copy Destination:=RngToSort.Offset(0, RngToSort.Columns.Count * 2) Dim RngCopy As range: Set RngCopy = RngToSort.Offset(0, RngToSort.Columns.Count * 2) 'RngCopy.Sort Key1:=RngCopy.Columns("A:A"), Order1:=xlAscending, MatchCase:=False RngCopy.Sort Key1:=RngCopy.Columns("A:A"), Order1:=xlDescending, MatchCase:=False Let RngCopy.Interior.Color = vbGreen End Sub
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 32WasB8 32WasB8 9bcde WasB9 6WasB7 6WasB7 10




Reply With Quote
Bookmarks