Insert 3 rows

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

Guest

I have a huge spreadsheet that I want to insert three copied rows between
each current line throughout the worksheet. I want to be able to halt the
macro when I get to the category so what I would like to do is insert 3
copied rows, move down one and insert three copied rows, move down,....

Please help
 
Rob,

Try something like

Dim RowNdx As Long
For RowNdx = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
Rows(RowNdx).Resize(3).Insert
Next RowNdx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Where are the three copied rows?
Is it a same copy region again and again for every inserts on every line?
Hope this has some help for you:

The code below does the following
1. Starts from the selection upwards and add three rows to every middle. You
can do this downwards also, but then you have to take into account the
inserted lines.
2. Copies a selection objFromRange to the new empty lines - this is lines
2-4 from sheet2 in the same workbook.
---8<---
Sub Macro1()
Dim objFromRange As Range 'This range points the lines to be copied
Dim iLineNumber As Long
With ActiveSheet
bCopyOrigin = True
Set objFromRange = Range("Sheet2!2:4")
For iLineNumber = Selection.Row() To 2 Step -1
Range(.Cells(iLineNumber, 1), .Cells(iLineNumber + 2,
1)).EntireRow.Insert xlShiftDown, False
.Cells(iLineNumber, 1).Select
objFromRange.Copy
.Paste 'Real paste to the cells
'.Cells(iLineNumber,1).PasteSpecial xlValues 'Pasting just values
Next
End With
End Sub
---8<---

Br, Mani
 

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