Private Sub CommandButton1_Click()
Dim x
x = Me.ListBox1.List
ReDim Preserve x(UBound(x), 0)
QuicksortA x, LBound(x), UBound(x), 0
Me.ListBox1.List = x
End Sub
Private Sub CommandButton2_Click()
Dim x
x = Me.ListBox1.List
ReDim Preserve x(UBound(x), 0)
QuicksortD x, LBound(x), UBound(x), 0
Me.ListBox1.List = x
End Sub
Private Sub QuicksortA(ary, LB, UB, ref)
Dim M As Variant, temp
Dim i As Long, ii As Long, iii As Integer
i = UB
ii = LB
M = UCase(ary(Int((LB + UB) / 2), ref))
Do While ii <= i
Do While UCase(ary(ii, ref)) < M
ii = ii + 1
Loop
Do While UCase(ary(i, ref)) > M
i = i - 1
Loop
If ii <= i Then
For iii = LBound(ary, 2) To UBound(ary, 2)
temp = ary(ii, iii): ary(ii, iii) = ary(i, iii)
ary(i, iii) = temp
Next
ii = ii + 1: i = i - 1
End If
Loop
If LB < i Then QuicksortA ary, LB, i, ref
If ii < UB Then QuicksortA ary, ii, UB, ref
End Sub
Private Sub QuicksortD(ary, LB, UB, ref)
Dim M As Variant, temp
Dim i As Long, ii As Long, iii As Integer
i = UB
ii = LB
M = UCase(ary(Int((LB + UB) / 2), ref))
Do While ii <= i
Do While UCase(ary(ii, ref)) > M
ii = ii + 1
Loop
Do While UCase(ary(i, ref)) < M
i = i - 1
Loop
If ii <= i Then
For iii = LBound(ary, 2) To UBound(ary, 2)
temp = ary(ii, iii): ary(ii, iii) = ary(i, iii)
ary(i, iii) = temp
Next
ii = ii + 1: i = i - 1
End If
Loop
If LB > i Then QuicksortA ary, LB, i, ref
If ii > UB Then QuicksortA ary, ii, UB, ref
End Sub