Hello to everyone.
I found this code wich help to sort by the items from listbox.
So I have a userform with Listbox and a button
The listbox is populated with dates.
Private Sub UserForm_Initialize()
With ListBox1
.AddItem "17.03.2021"
.AddItem "15.03.2021"
.AddItem "13.03.2021"
.AddItem "18.03.2021"
.AddItem "14.03.2021"
.AddItem "16.03.2021"
End sub
After I run this code the items are rearranged cronological:
13.03.2021
14.03.2021
15.03.2021
16.03.2021
17.03.2021
18.03.2021
Private Sub CommandButton1_Click()
Dim i As Long
Dim j As Long
Dim Temp As Variant
With ListBox2
For i = 0 To .ListCount - 2
For j = i + 1 To .ListCount - 1
If DateValue(List(i, 0)) > DateValue(.List(j, 0)) Then
Temp = .List(j, 0)
.List(j, 0) = .List(i, 0)
.List(i, 0) = Temp
End If
Next j
Next i
End With
End Sub
Question: Wich is vba code to create reverse sort of the dates ?
Something like that:
18.03.2021
17.03.2021
16.03.2021
15.03.2021
14.03.2021
13.03.2021
Thank's a lot.
I found this code wich help to sort by the items from listbox.
So I have a userform with Listbox and a button
The listbox is populated with dates.
Private Sub UserForm_Initialize()
With ListBox1
.AddItem "17.03.2021"
.AddItem "15.03.2021"
.AddItem "13.03.2021"
.AddItem "18.03.2021"
.AddItem "14.03.2021"
.AddItem "16.03.2021"
End sub
After I run this code the items are rearranged cronological:
13.03.2021
14.03.2021
15.03.2021
16.03.2021
17.03.2021
18.03.2021
Private Sub CommandButton1_Click()
Dim i As Long
Dim j As Long
Dim Temp As Variant
With ListBox2
For i = 0 To .ListCount - 2
For j = i + 1 To .ListCount - 1
If DateValue(List(i, 0)) > DateValue(.List(j, 0)) Then
Temp = .List(j, 0)
.List(j, 0) = .List(i, 0)
.List(i, 0) = Temp
End If
Next j
Next i
End With
End Sub
Question: Wich is vba code to create reverse sort of the dates ?
Something like that:
18.03.2021
17.03.2021
16.03.2021
15.03.2021
14.03.2021
13.03.2021
Thank's a lot.