Sub BubbleSort()
Dim tm!: tm = Timer
Dim x, tmp, i As Long, j As Long
x = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).Value
If UBound(x) > 5000 Then MsgBox "Больше 5000 сортировать не буду! Медленно.", 64: Exit Sub
For i = 1 To UBound(x)
For j = 1 To UBound(x) - i
If x(j, 1) > x(j + 1, 1) Then 'по возрастанию
' If x(j, 1) < x(j + 1, 1) Then 'по убыванию
tmp = x(j, 1)
x(j, 1) = x(j + 1, 1)
x(j + 1, 1) = tmp
End If
Next j
Next i
Range("D1").Resize(UBound(x)).Value = x
MsgBox Timer - tm
End Sub
|