autofill numbering range stick to range

  • I want to run an autofill numbering with macro that no blank rows in excel 2016 but if I run the autofill numbering it always stick to range (A1:A102) of my earlier data. How can the auto numbering range change to accomodate different data??


    Thanks


    Sub Macro1()
    '
    ' Macro1 Macro
    '


    '
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("A2").Select
    ActiveCell.FormulaR1C1 = "2"
    Range("A1:A2").Select
    Selection.AutoFill Destination:=Range("A1:A102")
    Range("A1:A102").Select
    End Sub

  • Re: autofill numbering range stick to range


    Hello,


    You do not need a macro for numbering rows ...


    Just go to A1 and input =Row() ... and copy down ... :wink:


    If you really want a macro ...


    Code
    Sub Macro1()
    Dim i As Long
      For i = 1 To 102
        Range("A" & i) = i
      Next i
    End Sub


    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Thumbs Up" icon, below, in the bottom right corner:)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!