ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting 2D portion of 5D Array (https://www.excelbanter.com/excel-programming/290172-sorting-2d-portion-5d-array.html)

ExcelMonkey[_68_]

Sorting 2D portion of 5D Array
 
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


Tom Ogilvy

Sorting 2D portion of 5D Array
 
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/




ExcelMonkey[_71_]

Sorting 2D portion of 5D Array
 
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/



All times are GMT +1. The time now is 10:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com