PDA

View Full Version : [SOLVED] Sort Alphabetically List Box



sheeeng
06-07-2005, 10:07 PM
Could anyone show me how to sort a list box alphabetically?

Thanks.:friends:

xCav8r
06-07-2005, 10:12 PM
How are you storing the data for the row source? (This was my 100th post! Yay!)

sheeeng
06-07-2005, 11:33 PM
I read the data from the column in excel worksheets "Sheet1" column "C".

How do I also to read the string value from the listbox with multiple selection?
For example, MsgBox() for every value that is selected.

Thanks.:friends:

sheeeng
06-08-2005, 09:51 PM
This is the solution that I used. Hope it can help everyone. :thumb


Function SortListBoxArray(ByRef vTemp As Variant)
Dim vArr(), vSArr() As String, vItm As Variant, i As Long
vArr = vTemp.List
i = 0
For Each vItm In vArr
ReDim Preserve vSArr(i)
vSArr(i) = vItm
i = i + 1
Next vItm
SortStringArray vSArr
vTemp.List = vSArr
End Function


Sub SortStringArray(x)
' Function: sorts virtually any data type from smallest to largest
' Limitations: assumes entire array from LBound(X) to UBound(X) is to be sorted
' Passed Values: X [in, any] array of values
Dim i As Long
Dim J As Long
Dim temp
Dim PerDone As Double
For i = LBound(x) To UBound(x) - 1
For J = i + 1 To UBound(x)
If x(i) > x(J) Then
temp = x(i)
x(i) = x(J)
x(J) = temp
End If
Next J
Next i
End Sub


Thanks. :beerchug: