Hi,
I have the following script that collects my data into an array and adds to a combo-box, However the data is unsorted. I found a script that is suppose to sort the array, However I'm not having any luck with it. it may be the way I am calling it or something else I cant see at the moment.
I'm looking to either sort the array then add the items to the combo-box or Just sort the items that are placed in the combo-box. Or maybe someone has another Idea...
Can someone please take a look and advise.
Thanks as always, Mike
Private Sub UserForm_Initialize()
Dim startrow As Long
Dim lastrow As Long
Dim myArray()
Dim a As Long
Dim i As Long
Dim myRowValue As String
Dim myColumn As Long
Dim Temp As Variant, X As Integer
myColumn = 249
startrow = 4
lastrow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
For i = startrow To lastrow
myRowValue = Cells(i, myColumn).Value
If myRowValue = "0" Or myRowValue = vbNullString Then
Else
ReDim Preserve myArray(a)
myArray(a) = myRowValue
a = a + 1
End If
Next
For N = LBound(myArray) To UBound(myArray)
ComboBox4.AddItem myArray(N)
Next
Stop
SortArray (myArray)
End Sub
The Sort Script...
Public Function SortArray(ByRef TheArray As Variant)
Sorted = False
Do While Not Sorted
Sorted = True
For X = 0 To UBound(TheArray) - 1
If TheArray(X) > TheArray(X + 1) Then
Temp = TheArray(X + 1)
TheArray(X + 1) = TheArray(X)
TheArray(X) = Temp
Sorted = False
End If
Next X
Loop
End Function
Bookmarks