LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default sorting an array

Hello,

I use a sorting function (BubbleSort) to sort an array of data. The array
is 3 dimentions and it is being sorted by the first. I want it to sort by
the first then the second. Can anyone help me with this?

Here is the code now:

Function BubbleSort(TempArray As Variant)

Dim temp(71, 3) As Variant
Dim i As Integer
Dim NoExchanges As Integer

' Loop until no more "exchanges" are made.

Do

NoExchanges = True

' Loop through each element in the array.

For i = 1 To UBound(TempArray) - 1

' If the element is greater than the element
' following it, exchange the two elements.

If TempArray(i, 1) TempArray(i + 1, 1) Then
NoExchanges = False

temp(i, 1) = TempArray(i, 1)
temp(i, 2) = TempArray(i, 2)
temp(i, 3) = TempArray(i, 3)

TempArray(i, 1) = TempArray(i + 1, 1)
TempArray(i, 2) = TempArray(i + 1, 2)
TempArray(i, 3) = TempArray(i + 1, 3)

TempArray(i + 1, 1) = temp(i, 1)
TempArray(i + 1, 2) = temp(i, 2)
TempArray(i + 1, 3) = temp(i, 3)

End If

Next i

Loop While Not (NoExchanges)

End Function

Thanks,
Ernst.

 
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 within an array Steve Excel Discussion (Misc queries) 1 May 31st 07 12:49 PM
Array Sorting in VB Randall[_4_] Excel Programming 1 August 24th 04 10:35 PM
Sorting 2D portion of 5D Array ExcelMonkey[_68_] Excel Programming 2 February 4th 04 04:04 AM
Sorting 2D Array ExcelMonkey[_28_] Excel Programming 14 January 28th 04 07:32 PM
Sorting a 2-dimensional array Vasant Nanavati[_2_] Excel Programming 3 July 12th 03 08:27 PM


All times are GMT +1. The time now is 05:09 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"