Quick and Easy: Copying and Inserting Lines Using VBA

  • Thread starter Thread starter Kristen
  • Start date Start date
K

Kristen

I have an easy one for you guys.... I want to use VBA to make a simple
loop that will go down the page in Excel in my current file and
duplicate each row, adding it into the row below it. Got any simple
VBA code?? I'm too tired to come up with it on my own! THank you!

Kristen
 
This code is sloppy and I'm sure there is some overkill in it, but it works.
The key is, before you run the code, you must click on the cell in column A
at which row you would like to start this process. If you want to start at
the top, just click on A1 to select the cell, and then run this code. This
will find the last row which has data in column A to determine how many
times the duplication process must repeat. If the last row to be duplicated
does not have data in column A of that row, you'll need to modify the code
slightly. Save you're work first.
HTH,
Paul


Sub Macro1()
i = Range("A65536").End(xlUp).Row
s = i - ActiveCell.Row + 1
c = 1

For r = 1 To i
ActiveCell.EntireRow.Select
Selection.Copy
Rows(Selection.Row & ":" & Selection.Row).Offset(1, 0).Select
Selection.Insert Shift:=xlDown
ActiveCell.Offset(1, 0).Select
If c = s Then End
c = c + 1
Next r
End Sub
 

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