'插入排序,从小到大
Sub 插入排序()
Dim arr, i, temp, y
arr = Range("a1:a18")
For i = 2 To UBound(arr)
temp = Cells(i, 1)
Range("a" & i).Interior.ColorIndex = 3
Range("a" & i).Interior.ColorIndex = ylNone
For y = i - 1 To 1 Step -1
Range("a" & y).Interior.ColorIndex = 5
Range("a" & y).Interior.ColorIndex = xlNone
If Cells(y, 1) >= temp Then
Cells(y + 1, 1) = Cells(y, 1)
Range("a" & y).Interior.ColorIndex = xlNone
Cells(y, 1) = temp
End If
Next y
Next i
End Sub
</
Sub 插入排序()
Dim arr, i, temp, y
arr = Range("a1:a18")
For i = 2 To UBound(arr)
temp = Cells(i, 1)
Range("a" & i).Interior.ColorIndex = 3
Range("a" & i).Interior.ColorIndex = ylNone
For y = i - 1 To 1 Step -1
Range("a" & y).Interior.ColorIndex = 5
Range("a" & y).Interior.ColorIndex = xlNone
If Cells(y, 1) >= temp Then
Cells(y + 1, 1) = Cells(y, 1)
Range("a" & y).Interior.ColorIndex = xlNone
Cells(y, 1) = temp
End If
Next y
Next i
End Sub
</