Add rows depend on the number in a cell

E

Elton Law

Dear Expert,
In A1, it has a number 3.
In A2, it has a number 5.
In A3, it has a number 4.
I want to run a marco that add 2 rows if A1 contains a number of 3.
It adds 4 rows if A2 contains a number of 5.
It adds 3 rows if A3 contains a number of 4.
After running, Number 3 will move to A3 (add 2 rows already).
Number 5 will move to A8 (add 4 rows already)
Number 4 will move to A12 (add 3 rows already)
Is it too difficult ?
Thanks in advance.
 
M

Mike H

Hi,

Right click your sheet tab, view code and paste this in and run it.

Sub addrows()
For x = 3 To 1 Step -1
For y = 1 To Cells(x, 1).Value - 1
Rows(x).EntireRow.Insert
Next
Next
End Sub

Mike
 
D

Don Guillett

try this
Sub insertvarrows()
mc = 1
For i = Cells(Rows.Count, mc).End(xlUp).Row To 1 Step -1
Rows(i).Resize(Cells(i, mc)).Insert
Next i
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

Top