Auto Increment Rows in between numbers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello.
I have a spreadsheet that has a list of numbers on the left side (Column A)
and I need to know how to create a macro that when I hit a button a row will
insert in between the list of numbers and automatically fill in the number
that goes there. If that makes sense. So if I have a list of 1-20 and I
insert a row between 15 and 16, it will put 16 in that cell and put 21 at the
end of the list. Thanks so much for you help.
 
Try this code...

Public Sub InsertARow()
Dim rngCurrent As Range
Dim rngToFill As Range

Set rngCurrent = Range("A" & ActiveCell.Row)
Set rngToFill = rngCurrent.End(xlDown)

rngCurrent.EntireRow.Insert
Set rngToFill = Range(rngCurrent.Offset(-2, 0), rngToFill)

rngCurrent.Offset(-2, 0).AutoFill rngToFill, xlFillSeries

End Sub

HTH
 
Thank you, works like a charm! That is awewsome.

Jim Thomlinson said:
Try this code...

Public Sub InsertARow()
Dim rngCurrent As Range
Dim rngToFill As Range

Set rngCurrent = Range("A" & ActiveCell.Row)
Set rngToFill = rngCurrent.End(xlDown)

rngCurrent.EntireRow.Insert
Set rngToFill = Range(rngCurrent.Offset(-2, 0), rngToFill)

rngCurrent.Offset(-2, 0).AutoFill rngToFill, xlFillSeries

End Sub

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top