Good afternoon, I obtained the following code today to sort the items populated in a ListBox:-
But it appears to be sorting the items that begin with a Capital Letter then sorting those that don't, e.g. C, F, J & Q followed by j & m.
Bearing in mind that I had to go & find this code in the first place, can anyone suggest, a) the reason for this behaviour & b) something to make it work the way that I think it should work?
Many thanks,
D€$
Code:
'Sort by the 1st column in the ListBox Alphabetically in Ascending Order
Run "SortListBox", UserForm2.ListBox1, 0, 1, 1
Sub SortListBox(oLb As MSForms.ListBox, sCol As Integer, sType As Integer, sDir As Integer)
Dim vaItems As Variant
Dim i As Long, j As Long
Dim c As Integer
Dim vTemp As Variant
'Put the items in a variant array
vaItems = oLb.List
'Sort the Array Alphabetically(1)
If sType = 1 Then
For i = LBound(vaItems, 1) To UBound(vaItems, 1) - 1
For j = i + 1 To UBound(vaItems, 1)
'Sort Ascending (1)
If sDir = 1 Then
If vaItems(i, sCol) > vaItems(j, sCol) Then
For c = 0 To oLb.ColumnCount - 1 'Allows sorting of multi-column ListBoxes
vTemp = vaItems(i, c)
vaItems(i, c) = vaItems(j, c)
vaItems(j, c) = vTemp
Next c
End If
.
.
.
'Set the list to the array
oLb.List = vaItems
End Sub
But it appears to be sorting the items that begin with a Capital Letter then sorting those that don't, e.g. C, F, J & Q followed by j & m.
Bearing in mind that I had to go & find this code in the first place, can anyone suggest, a) the reason for this behaviour & b) something to make it work the way that I think it should work?
Many thanks,
D€$