Public Sub BubbleSort()
Dim tempVar As Integer
Dim anotherIteration As Boolean
Dim I As Integer
Dim iterationNum As Integer
Dim sortArray(10) As Integer
For I = 2 To 11
sortArray(I - 2) = Cells(I, "A").Value
Next I
Do
anotherIteration = False
For I = 0 To 8
If sortArray(I) > sortArray(I + 1) Then
tempVar = sortArray(I)
sortArray(I) = sortArray(I + 1)
sortArray(I + 1) = tempVar
anotherIteration = True
End If
Next I
iterationNum = iterationNum + 1
Cells(1, iterationNum + 2).Value = iterationNum
For I = 0 To 9
Cells(I + 2, iterationNum + 2).Value = sortArray(I)
Next I
Loop While anotherIteration = True
End Sub
|