Citation :
Public Function sort_col(ByRef rRange As Range) As Variant
Dim i As Integer
Dim flag_sorted As Boolean
Dim temp As Variant
Dim save1 As Variant, save2 As Variant
temp = rRange.Value
Do
flag_sorted = True
For i = LBound(temp, 1) To UBound(temp, 1) - 1
If temp(i + 1, 1) < temp(i, 1) Then
save1 = temp(i, 1)
save2 = temp(i, 2)
temp(i, 1) = temp(i + 1, 1)
temp(i, 2) = temp(i + 1, 2)
temp(i + 1, 1) = save1
temp(i + 1, 2) = save2
flag_sorted = False
End If
Next i
Loop Until flag_sorted = True
sort_col = temp
End Function
|