Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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/

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting a portion of a worksheet NicoleS Excel Worksheet Functions 1 April 29th 10 09:37 AM
Sorting within an array Steve Excel Discussion (Misc queries) 1 May 31st 07 12:49 PM
Sorting a portion of a range gbeard Excel Worksheet Functions 1 April 23rd 05 01:51 PM
Sorting 2D Array ExcelMonkey[_28_] Excel Programming 14 January 28th 04 07:32 PM
Sorting Names in an Array Philippe Lhermie Excel Programming 6 July 20th 03 02:40 PM


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"