您的位置:首页 > 编程语言 > VB

VBA 第12课 插入排序

2015-10-05 23:38 435 查看


'插入排序,从小到大


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



转载请注明

作者与出处:http://blog.csdn.net/u013511642 王小涛_同學
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: