Sorting 2D portion of 5D Array

  • Thread starter Thread starter ExcelMonkey
  • Start date Start date
E

ExcelMonkey

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
 
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
 
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.
 
Back
Top