View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Toppers Toppers is offline
external usenet poster
 
Posts: 4,339
Default Sort Data in a combobox list

Hi,

Will this help?

your code ..... then add ...

ReDim myarray(1 To myval.Count)

For i = 1 To myval.Count
myarray(i) = myval(i)
Next i

BubbleSort myarray
ComboBox1.List = myarray


Sub BubbleSort(List() As Variant)
' 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 List(i) List(j) Then
Temp = List(j)
List(j) = List(i)
List(i) = Temp
End If
Next j
Next i
End Sub


"Kryer" wrote:

Private Sub UserForm_Initialize()
Dim sh As Worksheet
Dim rng As Range
Dim myval As Range
Dim myarray() As Variant

Range("C1").Select
Do Until ActiveCell = "GS"
Selection.End(xlDown).Select
Loop
Selection.Offset(1, 0).Select


Set sh = Workbooks("Book1.xls").Worksheets("Sheet1")
Set myval = Range(Selection, Selection.End(xlDown).Offset(1, 0))
Set rng = myval
myarray = rng
ComboBox1.List = myarray
End Sub

I am trying to figure out how to make this selection post a sorted ascending
list in the combobox on initialize. the combobox range varies in as many
listings as in names available. This could list from 100 - 200 names on any
given day and having to run thru this list unorganized is a nitemare. Any help