从单元格<> A1开始的数字序列

时间:2019-01-23 18:44:54

标签: excel vba

想要从单元格A4开始的序列。因此A4为1,A5为2,与A1004 = 1004

尝试将[Range(“ A”&I)..]更改为[Range(“ A4”&I)..] 尝试更改I = 4

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim I As Integer
    I = 1
    Application.EnableEvents = False
    For I = 1 To 1000
        Range("A" & I).Value = I
    Next
    Range("A1010").Value = ""
    Application.EnableEvents = True

End Sub

1 个答案:

答案 0 :(得分:0)

Sub Worksheet_Change(ByVal Target As Range)
Dim I As Integer
Set startRng = Cells(4, 1)

Application.EnableEvents = False
For I = 0 To 999
    startRng.Offset(I, 0) = I
Next
Range("A1010").Value = ""
Application.EnableEvents = True

End Sub