Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I had a 2D array which I sorted descending using the 9th column. I hav
now expanded the array to include 5 elements. I still want to sort th array as I originally did but am not sure what changes I have to mak to the call statment and the bubble sort to ensure that code contintue to simply sort the 2D portion of the array. The working code below i what I have for the original 2D array. Call BubbleSort2D(UnitOfferArray, 9) Function BubbleSort2D(UnitOfferArray As Variant, col As Long) ' Sorts an array using bubble sort algorithm in descending order usin column as sort criteria Dim First As Integer, Last As Integer Dim i As Integer, j As Integer Dim Temp As Variant First = LBound(UnitOfferArray, 1) Last = UBound(UnitOfferArray, 1) For i = 1 To Last - 1 For j = i + 1 To Last If UnitOfferArray(i, col) < UnitOfferArray(j, col) Then For k = 1 To UBound(UnitOfferArray, 2) Temp = UnitOfferArray(j, k) UnitOfferArray(j, k) = UnitOfferArray(i, k) UnitOfferArray(i, k) = Temp Next k End If Next j Next i End Functio -- Message posted from http://www.ExcelForum.com |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Call BubbleSort2D(UnitOfferArray, 9)
Function BubbleSort2D(UnitOfferArray As Variant, col As Long,a,b,c) ' Sorts an array using bubble sort algorithm in descending order using column as sort criteria Dim First As Integer, Last As Integer Dim i As Integer, j As Integer Dim Temp As Variant First = LBound(UnitOfferArray, 1) Last = UBound(UnitOfferArray, 1) For i = 1 To Last - 1 For j = i + 1 To Last If UnitOfferArray(i, col,a,b,c) < UnitOfferArray(j, col,a,b,c) Then For k = 1 To UBound(UnitOfferArray, 2) Temp = UnitOfferArray(j, k,a,b,c) UnitOfferArray(j, k,a,b,c) = UnitOfferArray(i, k,a,c,b) UnitOfferArray(i, k,a,b,c Temp Next k End If Next j Next i End Function -- Regards, Tom Ogilvy ExcelMonkey wrote in message ... I had a 2D array which I sorted descending using the 9th column. I have now expanded the array to include 5 elements. I still want to sort the array as I originally did but am not sure what changes I have to make to the call statment and the bubble sort to ensure that code contintues to simply sort the 2D portion of the array. The working code below is what I have for the original 2D array. Call BubbleSort2D(UnitOfferArray, 9) Function BubbleSort2D(UnitOfferArray As Variant, col As Long) ' Sorts an array using bubble sort algorithm in descending order using column as sort criteria Dim First As Integer, Last As Integer Dim i As Integer, j As Integer Dim Temp As Variant First = LBound(UnitOfferArray, 1) Last = UBound(UnitOfferArray, 1) For i = 1 To Last - 1 For j = i + 1 To Last If UnitOfferArray(i, col) < UnitOfferArray(j, col) Then For k = 1 To UBound(UnitOfferArray, 2) Temp = UnitOfferArray(j, k) UnitOfferArray(j, k) = UnitOfferArray(i, k) UnitOfferArray(i, k) = Temp Next k End If Next j Next i End Function --- Message posted from http://www.ExcelForum.com/ |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Correction: I mistakenly said 5 elements when I meant 5 dimensions.
See below: I had a 2D array which I sorted descending using the 9th column. I have now expanded the array to include 5 elements. I still want to sort the array as I originally did but am not sure what changes I have to make to the call statment and the bubble sort to ensure that code contintues to simply sort the 2D portion of the array. The working code below is what I have for the original 2D array. --- Message posted from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Sorting a portion of a worksheet | Excel Worksheet Functions | |||
Sorting within an array | Excel Discussion (Misc queries) | |||
Sorting a portion of a range | Excel Worksheet Functions | |||
Sorting 2D Array | Excel Programming | |||
Sorting Names in an Array | Excel Programming |