Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to sort ListBox or Array?

Is there any easy way the best build in VBA.....lets to sort listbox /
combocox or array?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to sort ListBox or Array?

Sort your data before you put it in the combobox


Sub Tester11a()
Dim vArr as Variant
Dim rng as Range
Set rng = Range("I7").CurrentRegion
vArr = rng.Value
QuickSort vArr, 5, LBound(vArr, 1), UBound(vArr, 1)
Userform1.Combobox1.List = vArr
End Sub


Sub QuickSort(SortArray, col, L, R)
'
'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)
Dim i, j, X, Y, mm
' Usage Quicksort Array to sort, column to sort on, Lowest row, Highest
row


i = L
j = R
X = SortArray((L + R) / 2, col)


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
If (L < j) Then Call QuickSort(SortArray, col, L, j)
If (i < R) Then Call QuickSort(SortArray, col, i, R)
End Sub


--
Regards,
Tom Ogilvy


"NEED" wrote in message
...
Is there any easy way the best build in VBA.....lets to sort listbox /
combocox or array?




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
Array to Populate ListBox Problem pallaver Excel Discussion (Misc queries) 1 July 25th 08 08:50 AM
Sort Listbox Items Stratuser Excel Programming 2 January 17th 04 03:05 PM
ListBox array Neil Excel Programming 1 November 24th 03 11:34 AM
populating multicolumn listbox with an array instead of... notsureofthatinfo Excel Programming 0 November 5th 03 10:18 PM
Listbox and Array questions Stuart[_5_] Excel Programming 4 September 23rd 03 11:04 PM


All times are GMT +1. The time now is 01:08 AM.

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"