Option Explicit
Sub TEST2()
Dim ar, i&, p&
Application.ScreenUpdating = False
With Worksheets(1).[A1].CurrentRegion
ar = .Resize(.Rows.Count + 1).Value
bSort ar, 2, UBound(ar), 1, UBound(ar, 2), UBound(ar, 2), False
p = 2
For i = 2 To UBound(ar) - 1
If ar(i + 1, UBound(ar, 2)) <> ar(p, UBound(ar, 2)) Then
bSort ar, p, i, 1, UBound(ar, 2), 4, False
p = i + 1
End If
Next i
End With
With Worksheets(2)
.Cells.Clear
.[A1].Resize(UBound(ar), UBound(ar, 2)) = ar
.Activate
End With
Application.ScreenUpdating = True
Beep
End Sub
Function bSort(ByRef ar, ByVal iFirst&, ByVal iLast&, ByVal iLeft&, _
ByVal iRight&, ByVal iKey&, Optional isOrder As Boolean = True)
Dim i&, j&, k&, vTemp
For i = iFirst To iLast - 1
For j = iFirst To iLast + iFirst - 1 - i
If ar(j, iKey) <> ar(j + 1, iKey) Then
If ar(j, iKey) < ar(j + 1, iKey) Xor isOrder Then
For k = iLeft To iRight
vTemp = ar(j, k)
ar(j, k) = ar(j + 1, k)
ar(j + 1, k) = vTemp
Next
End If
End If
Next j
Next i
End Function
|