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  王小涛_同學

猜你喜欢

转载自blog.csdn.net/u013511642/article/details/48920719
vba