[Excel VBA]单元格更改后自动排序

项目正好用到,记录一下,excel 2007 测试通过。

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 Then
        i = Selection.Row
        j = Selection.Column

        Range("A6").Select
        Selection.Sort Key1:=Range("A6"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
        :=xlPinYin, DataOption1:=xlSortNormal
        Cells(i, j).Select
    End If
End Sub
评论关闭

return top