Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Sorting Arrays

Is there a quick way to sort a single dimensional array? Multi-dimensional
array?
Thanks.

Bernie


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Sorting Arrays

Bernie,

Stephen Bullen has a good collection of QuickSort routines:
http://www.bmsltd.co.uk/Excel/SBXLPage.asp#VBA

Rob


"B Tuohy" wrote in message
...
Is there a quick way to sort a single dimensional array? Multi-dimensional
array?
Thanks.

Bernie




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sorting Arrays

http://support.microsoft.com/default...17&Product=vb6
HOWTO: Sort Algorithms for Numeric Arrays

Here is some code I have modified to do it.

The second procedure shows how to call the quicksort.

Sub QuickSort(SortArray, col, L, R, bAscending)
'
'Originally Posted by Jim Rech 10/20/98 Excel.Programming
'Modified to sort on first column of a two dimensional array
'Modified to handle a second dimension greater than 1 (or zero)
'Modified to sort on a specified column in a 2D array
'Modified to do Ascending or Descending
Dim i, j, X, Y, mm

i = L
j = R
X = SortArray((L + R) / 2, col)
If bAscending Then
While (i <= j)
While (SortArray(i, col) < X And i < R)
i = i + 1
Wend
While (X < SortArray(j, col) And j L)
j = j - 1
Wend
If (i <= j) Then
For mm = LBound(SortArray, 2) To UBound(SortArray, 2)
Y = SortArray(i, mm)
SortArray(i, mm) = SortArray(j, mm)
SortArray(j, mm) = Y
Next mm
i = i + 1
j = j - 1
End If
Wend
Else
While (i <= j)
While (SortArray(i, col) X And i < R)
i = i + 1
Wend
While (X SortArray(j, col) And j L)
j = j - 1
Wend
If (i <= j) Then
For mm = LBound(SortArray, 2) To UBound(SortArray, 2)
Y = SortArray(i, mm)
SortArray(i, mm) = SortArray(j, mm)
SortArray(j, mm) = Y
Next mm
i = i + 1
j = j - 1
End If
Wend
End If
If (L < j) Then Call QuickSort(SortArray, col, L, j, bAscending)
If (i < R) Then Call QuickSort(SortArray, col, i, R, bAscending)
End Sub




Sub aaTesterSort()
Dim bAscending As Boolean
Set rng = Range("I7").CurrentRegion
vArr = rng.Value
bAscending = False
QuickSort vArr, 5, LBound(vArr, 1), UBound(vArr, 1), bAscending
Range("I26").Resize(UBound(vArr, 1), UBound(vArr, 2)).Value = vArr
End Sub

--
Regards,
Tom Ogilvy


B Tuohy wrote in message
...
Is there a quick way to sort a single dimensional array? Multi-dimensional
array?
Thanks.

Bernie




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorting Arrays

Hi Bernie,

I found this thread before..there are many ways of sorting arrays.
(As far as I saw, 1-D array only)

http://www.visualbasicforum.com/t78889.html


---
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
Arrays Abdul Shakeel Excel Worksheet Functions 1 December 12th 08 10:24 AM
Arrays [email protected] Setting up and Configuration of Excel 3 February 18th 05 02:43 AM
List boxes, Arrays and Sorting Stuart[_15_] Excel Programming 2 December 23rd 03 06:49 PM
Arrays drtaclem Excel Programming 0 December 10th 03 07:55 PM
VBA: Sorting arrays in hierarchichal data structu Help!!! Karen Lee Excel Programming 6 September 24th 03 05:14 PM


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

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"