Hi there,
I've found the following code elsewhere; it sorts a multicolumn listbox in ascending order, based on the values in column 1. It works fine, but I'd like the code to be adapted so that it sorts the listbox based on the values in column 2. I´d be very happy if anyone could help me with this. Thanks in advance.
I've found the following code elsewhere; it sorts a multicolumn listbox in ascending order, based on the values in column 1. It works fine, but I'd like the code to be adapted so that it sorts the listbox based on the values in column 2. I´d be very happy if anyone could help me with this. Thanks in advance.
Code:
Private Sub SorteerNaam_Click()
Dim i As Long
Dim j As Long
Dim sTemp As String
Dim sTemp2 As String
Dim LbList As Variant
LbList = Me.Overzicht.List
For i = LBound(LbList, 1) To UBound(LbList, 1) - 1
For j = i + 1 To UBound(LbList, 1)
If LbList(i, 0) > LbList(j, 0) Then
sTemp = LbList(i, 0)
LbList(i, 0) = LbList(j, 0)
LbList(j, 0) = sTemp
sTemp2 = LbList(i, 1)
LbList(i, 1) = LbList(j, 1)
LbList(j, 1) = sTemp2
sTemp3 = LbList(i, 2)
LbList(i, 2) = LbList(j, 2)
LbList(j, 2) = sTemp3
sTemp4 = LbList(i, 3)
LbList(i, 3) = LbList(j, 3)
LbList(j, 3) = sTemp4
sTemp5 = LbList(i, 4)
LbList(i, 4) = LbList(j, 4)
LbList(j, 4) = sTemp5
sTemp6 = LbList(i, 5)
LbList(i, 5) = LbList(j, 5)
LbList(j, 5) = sTemp6
End If
Next j
Next i
Me.Overzicht.Clear
Me.Overzicht.List = LbList
End Sub