Insert blank row after every nth row

unknownymous

Board Regular
Joined
Sep 19, 2017
Messages
249
Office Version
  1. 2016
Platform
  1. Windows
Hello Guys,

I have long list of data and I want to insert a blank row after every nth row for example after. Below is the sample initial illustration. I need to add starting


A1
A2IDNameScore
A3
A4001BEN5

<tbody>
</tbody>


The data starts in A4 onwards and what I need is to add blank in every 5th row. Can you possibly help me modify below codes?

Sub InsertRowEveryXrows()
Dim r As Long, lr As Long
lr = Range("B" & Rows.Count).End(xlUp).Row
For r = 4 To lr Step 10
Rows(r).Insert Shift:=xlDown
Next r
End Sub



Any help will be much appreciated (beginner here). Thanks!
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Your title calls for inserting a blank ROW, while your posted code inserts a blank cell in the row. The code below inserts blank cells, but see the comment if you want to insert entire rows.
Rich (BB code):
Sub EveryNthRowInsert()
Const n As Long = 5 'set n here
Dim R As Range, InsertRng As Range
Set R = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row)
For i = n To R.Rows.Count Step n
    If Not InsertRng Is Nothing Then
        Set InsertRng = Union(InsertRng, R(i))
    Else
        Set InsertRng = R(i)
    End If
Next i
Application.ScreenUpdating = False
If Not InsertRng Is Nothing Then InsertRng.Insert shift:=xlDown  'Change to Insertrng.EntireRow.Insert if you want to insert entire rows
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Thanks for this Joe. I use below codes:

Sub EveryNthRowInsert()
Const n As Long = 5 'set n here
Dim R As Range, InsertRng As Range
Set R = Range("c5:c" & Cells(Rows.Count, "c").End(xlUp).Row)
For i = n To R.Rows.Count Step n
If Not InsertRng Is Nothing Then
Set InsertRng = Union(InsertRng, R(i))
Else
Set InsertRng = R(i)
End If
Next i
Application.ScreenUpdating = False
If Not InsertRng Is Nothing Then InsertRng.EntireRow.Insert shift:=xlDown 'Change to Insertrng.EntireRow.Insert if you want to insert entire rows
Application.ScreenUpdating = True
End Sub


One more thing, what if I want to do below actions:

Let's say:

From A4 to A8 - A blank row in A9
From A10 to A19 - A blank row in A20
From A21to A40 - A blank row in A41


Thanks a lot in advance for the help.
 
Upvote 0
Thanks for this Joe.

One more thing, what if I want to do below actions:

Let's say:

From A4 to A8 - A blank row in A9
From A10 to A19 - A blank row in A20
From A21to A40 - A blank row in A41


Thanks a lot in advance for the help.
You are welcome.

What's the logic you are using to choose those rows? Doesn't appear they follow any consistent pattern.
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top