# Insert X rows below row Y based on value in row Y

#### lwhyatt

##### New Member
How can I get Excel to insert x rows below a row based on the value of a cell in that row?

eg if in row 1 cell B1 contains '5' I want 5 rows inserted.

I have a number of rows with different values so I need different gaps inserted between rows.

### Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a \$25,000 loan, 5% annual interest, 60 month loan.

#### mrshl9898

##### Well-known Member
Does this work for you?

Code:
``````Sub addrows()

Dim rownum As Long

rownum = 1

Do Until Cells(rownum, 2).Value = ""
Rows(rownum + 1 & ":" & addrow + rownum).Insert Shift:=xlDown
rownum = rownum + addrow + 1
Loop

End Sub``````

#### lwhyatt

##### New Member
Great thanks. It's adding one too many rows each time though as I want to re-use the first row. What do I change if the cells specifying the number of rows to add are in I4:I439 ?

#### DanteAmor

##### Well-known Member
Try this

Code:
``````Sub Macro2()
Dim i As Long, n As Long
For i = Range("I" & Rows.Count).End(xlUp).Row To 4 Step -1
n = Cells(i, "I").Value
If n > 0 Then Rows(i + 1 & ":" & i + n).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Next
End Sub``````

Replies
2
Views
217
Replies
3
Views
67
Replies
0
Views
132
Replies
1
Views
83
Replies
3
Views
107

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,163,713
Messages
5,833,269
Members
430,200
Latest member

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back