Combobox

  • Thread starter Thread starter Tony G
  • Start date Start date
T

Tony G

Is there any way that l can sort items in a combobox,
without having to sort the data from the named ranged.

TYIA

Tony G
 
sort the list before you put it in the listbox

varr = Range(cells(1,1),cells(1,1).End(xldown))
Quicksort2 varr, 1, lbound(varr,1) ubound(varr,1)
Listbox1.List = varr




Sub QuickSort2(SortArray, col, L, R)
'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 a second dimension greater than 1 (or zero)
Dim i, j, X, Y, mm

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