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

Is there a VB function to sort an array? Something like:

AA(0) = 3
AA(1) = 6
AA(2) = 0

Call ArraySort(AA)

Result:
AA(0) = 0
AA(1) = 3
AA(2) = 6

I can write my array to cells and uses Range.Sort, or
write my own ArraySort routein; but is there any way more
efficient than this?

Tx,

Randall
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Array Sorting in VB

Randall

one way:

Sub BubbleSort(List() As String)
'' Sorts the List array in ascending order
Dim First As Integer, Last As Integer
Dim i As Integer, j As Integer
Dim Temp

First = LBound(List)
Last = UBound(List)
For i = First To Last - 1
For j = i + 1 To Last
If UCase(List(i)) UCase(List(j)) Then
Temp = List(j)
List(j) = List(i)
List(i) = Temp
End If
Next j
Next i
End Sub

This is from a routine to sort worksheet names - found on the xl-logic.com
site.

I seem to recall one of the MVPs had examples of sorting single and two
dimensional arrays ... but off the top of my head I can't think where they
are.

Regards

Trevor


"Randall" wrote in message
...
Is there a VB function to sort an array? Something like:

AA(0) = 3
AA(1) = 6
AA(2) = 0

Call ArraySort(AA)

Result:
AA(0) = 0
AA(1) = 3
AA(2) = 6

I can write my array to cells and uses Range.Sort, or
write my own ArraySort routein; but is there any way more
efficient than this?

Tx,

Randall



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 array formula driller Excel Worksheet Functions 2 July 7th 08 12:10 AM
Sorting within an array Steve Excel Discussion (Misc queries) 1 May 31st 07 12:49 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 Names in an Array Philippe Lhermie Excel Programming 6 July 20th 03 02:40 PM


All times are GMT +1. The time now is 03:38 PM.

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

About Us

"It's about Microsoft Excel"