VBA 第12課 插入排序

'插入排序,從小到大

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  王小濤_同學
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章