LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default sort items of listboxes with multiple columns

Thank you very much!

"Tom Ogilvy" wrote:

There is no built in support for sorting data in listboxes, so you would
have to either sort it before putting it in, sort it as you put it in, or
sort it in the list.

Here is some code to sort an array. .

The second procedure shows how to call it.

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 sort on single column
'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

"borg" wrote in message
...
Hi,

I have 2 questions that are related.

I would like to sort the items in a listbox that contains 3 columns. What
is the code to sort by the first column, 2nd column, and 3rd column? Or

do I
have to sort the data first before I put it into the columns of the

listbox?

Secondly, is there a way to sort the values in an array after the values
have been stored in the array?

Thank you for the help!




 
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
Counting totals between multiple columns for like items Bernie R. Excel Worksheet Functions 9 February 14th 08 11:40 PM
Transferring items between multicolumn listboxes [email protected] Excel Discussion (Misc queries) 2 September 28th 07 03:09 PM
Sort and Match like Items in 2 Columns blaylock Excel Worksheet Functions 2 July 26th 06 09:32 PM
How can I count items in multiple columns with different criteria. ChileRed Excel Worksheet Functions 0 March 21st 06 07:15 PM
Listboxes and select items in it droopy928gt[_4_] Excel Programming 6 March 3rd 06 12:32 PM


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