Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

 How to insert specific number of rows at fixed intervals in Excel?

In Excel worksheet, you can insert a blank row between existing rows by using Insert function. But, if you have a large range of data, and, you need to insert two blank rows after every third rows, how could you finish this job quickly and conveniently?

Insert specific number of rows into data at fixed intervals with VBA code

Insert specific number of rows into data at fixed intervals with Kutools for Excel



The following VBA code can help you to insert a specific number of rows after every nth row within existing data. Please do as follows:

1. Hold down the ALT + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Insert specific number of rows into data at fixed intervals

Sub InsertRowsAtIntervals()
'Updateby20150707
Dim Rng As Range
Dim xInterval As Integer
Dim xRows As Integer
Dim xRowsCount As Integer
Dim xNum1 As Integer
Dim xNum2 As Integer
Dim WorkRng As Range
Dim xWs As Worksheet
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
xRowsCount = WorkRng.Rows.Count
xInterval = Application.InputBox("Enter row interval. ", xTitleId, 1, Type:=1)
xRows = Application.InputBox("How many rows to insert at each interval? ", xTitleId, 1, Type:=1)
xNum1 = WorkRng.Row + xInterval
xNum2 = xRows + xInterval
Set xWs = WorkRng.Parent
For i = 1 To Int(xRowsCount / xInterval)
    xWs.Range(xWs.Cells(xNum1, WorkRng.Column), xWs.Cells(xNum1 + xRows - 1, WorkRng.Column)).Select
    Application.Selection.EntireRow.Insert
    xNum1 = xNum1 + xNum2
Next
End Sub

3. After pasting this code, please press F5 key to run this code, a prompt box will pop out to remain you selecting the data range that you want to insert blank row, see screenshot:

doc insert rows at intervals 1

4. Click OK button, another prompt box will pop out, please enter the number of row intervals, see screenshot:

doc insert rows at intervals 2

5. Go on clicking OK button, in the following popped out prompt box, please enter the number of blank rows that you want to insert, see screenshot:

doc insert rows at intervals 3

6. Then click OK, and the blank rows have been inserted into the existing data at a regular intervals, see screenshot:

doc insert rows at intervals 4


If you are not familiar with above VBA code, Kutools for Excel also may help you, its Insert Blank Rows & Columns feature can insert specific number of rows or columns into existing data at fixed intervals quickly and easily.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 60 days

After installing Kutools for Excel, please do as follows:

1. Select the data range that you want to insert blank rows at intervals.

2. Click Kutools > Insert > Insert Blank Rows & Columns, see screenshot:

doc insert rows at intervals 5 5

3. In the Insert Blank Row & Columns dialog box, choose Blank rows or Blank columns you need, from the Insert type, and then specify the number of interval and blank rows that you want to use as following screenshot shown:

doc insert rows at intervals 6

4. Then click OK button, and the blank rows have been inserted into the selected range at a specific interval as following screenshot shown:

doc insert rows at intervals 7

Click to know more about this Insert Blank Row & Columns utility.

Download and free trial Kutools for Excel Now !


Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Conk · 15 days ago
    Gold bless you
  • To post as a guest, your comment is unpublished.
    SPGupta · 1 months ago
    How to add rows in excel data as per mentioned number in last cell say in a excel data if last cell is showing number as 4 , what is the way to dd 4 rows automtically. in another row number is 72, etc
    • To post as a guest, your comment is unpublished.
      skyyang · 1 months ago
      Hi, SPGupta,
      To insert blank rows based on specific number list, please apply the below VBA code.
      Please try, hope it can help you!

      Sub Insert()
      'UpdatebyExtendoffice
      Dim xRg As Range
      Dim xAddress As String
      Dim I, xNum, xLastRow, xFstRow, xCol, xCount As Long
      On Error Resume Next
      xAddress = ActiveWindow.RangeSelection.Address
      Set xRg = Application.InputBox("Select the spefic number column to use(single column):", "KuTools For Excel", xAddress, , , , , 8)
      If xRg Is Nothing Then Exit Sub
      Application.ScreenUpdating = False
      xLastRow = xRg(1).End(xlDown).Row
      xFstRow = xRg.Row
      xCol = xRg.Column
      xCount = xRg.Count
      Set xRg = xRg(1)
      For I = xLastRow To xFstRow Step -1
      xNum = Cells(I, xCol)
      If IsNumeric(xNum) And xNum > 0 Then
      Rows(I + 1).Resize(xNum).Insert
      xCount = xCount + xNum
      End If
      Next
      xRg.Resize(xCount, 1).Select
      Application.ScreenUpdating = True
      End Sub
      • To post as a guest, your comment is unpublished.
        Nina · 17 days ago
        Hi, could you help me, please? How can I change this code to ad one more less rows than number in cell? For example, if number in cell is 4, program add 3 rows. If number in cell is 1, rows are not aded
        • To post as a guest, your comment is unpublished.
          skyyang · 8 days ago
          Hi, Nina,
          To solve your task, please use the below code:

          Sub Insert()
          'UpdatebyExtendoffice
          Dim xRg As Range
          Dim xAddress As String
          Dim I, xNum, xLastRow, xFstRow, xCol, xCount As Long
          On Error Resume Next
          xAddress = ActiveWindow.RangeSelection.Address
          Set xRg = Application.InputBox("Select the spefic number column to use(single column):", "KuTools For Excel", xAddress, , , , , 8)
          If xRg Is Nothing Then Exit Sub
          Application.ScreenUpdating = False
          xLastRow = xRg(1).End(xlDown).Row
          xFstRow = xRg.Row
          xCol = xRg.Column
          xCount = xRg.Count
          Set xRg = xRg(1)
          For I = xLastRow To xFstRow Step -1
          xNum = Cells(I, xCol)
          xNum = xNum - 1
          If IsNumeric(xNum) And xNum > 0 Then
          Rows(I + 1).Resize(xNum).Insert
          xCount = xCount + xNum
          End If
          Next
          xRg.Resize(xCount, 1).Select
          Application.ScreenUpdating = True
          End Sub


          Please try, hope it can help you!
          • To post as a guest, your comment is unpublished.
            Nina · 7 days ago
            It works perfect, thank you so much!
  • To post as a guest, your comment is unpublished.
    PK · 10 months ago
    hi how can I get the code for Insert specific number of columns into data at fixed intervals
    • To post as a guest, your comment is unpublished.
      skyyang · 10 months ago
      Hello, PK,
      To insert blank columns into existing data at specific intervals, the below VBA code can help you! Please try it.

      Sub InsertColumnsAtIntervals()
      Dim Rng As Range
      Dim xInterval As Integer
      Dim xCs As Integer
      Dim xCCount As Integer
      Dim xNum1 As Integer
      Dim xNum2 As Integer
      Dim WorkRng As Range
      Dim xWs As Worksheet
      xTitleId = "KutoolsforExcel"
      Set WorkRng = Application.Selection
      Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
      xCCount = WorkRng.Columns.Count
      xInterval = Application.InputBox("Enter column interval. ", xTitleId, 1, Type:=1)
      xCs = Application.InputBox("How many columns to insert at each interval? ", xTitleId, 1, Type:=1)
      xNum1 = WorkRng.Column + xInterval
      xNum2 = xCs + xInterval
      Set xWs = WorkRng.Parent
      For I = 1 To Int(xCCount / xInterval)
      xWs.Range(xWs.Cells(WorkRng.Row, xNum1 + xCs - 1), xWs.Cells(WorkRng.Row, xNum1)).Select
      Application.Selection.EntireColumn.Insert
      xNum1 = xNum1 + xNum2
      Next
      End Sub
  • To post as a guest, your comment is unpublished.
    Martin · 1 years ago
    Fantastic - you saved me a lot of mindless data entry, thank you very much
  • To post as a guest, your comment is unpublished.
    Manish · 1 years ago
    Hi


    I use interval vba code its working..But when I use above 100000 rows it not working.. kindly suggest what should I change if any.


    Sub InsertRowsAtIntervals()
    'Updateby20150707
    Dim Rng As Range
    Dim xInterval As Integer
    Dim xRows As Integer
    Dim xRowsCount As Integer
    Dim xNum1 As Integer
    Dim xNum2 As Integer
    Dim WorkRng As Range
    Dim xWs As Worksheet
    xTitleId = "KutoolsforExcel"
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
    xRowsCount = WorkRng.Rows.Count
    xInterval = Application.InputBox("Enter row interval. ", xTitleId, 1, Type:=1)
    xRows = Application.InputBox("How many rows to insert at each interval? ", xTitleId, 1, Type:=1)
    xNum1 = WorkRng.Row + xInterval
    xNum2 = xRows + xInterval
    Set xWs = WorkRng.Parent
    For i = 1 To Int(xRowsCount / xInterval)
    xWs.Range(xWs.Cells(xNum1, WorkRng.Column), xWs.Cells(xNum1 + xRows - 1, WorkRng.Column)).Select
    Application.Selection.EntireRow.Insert
    xNum1 = xNum1 + xNum2
    Next
    End Sub
  • To post as a guest, your comment is unpublished.
    Atif · 2 years ago
    Thanks AloT!!
  • To post as a guest, your comment is unpublished.
    Stephanie · 2 years ago
    thank you so much!!!!! this is amazing
  • To post as a guest, your comment is unpublished.
    Farooq · 3 years ago
    Hi,

    I'm using your code (below) can you please tell me how can fill those rows with custom text into it. I've used your code to enter three rows it worked perfectly but now I need to enter the text

    Row1 = Date
    Row2.= Location
    Row3 = Phone Number

    Thanks in advance...



    "Sub InsertRowsAtIntervals()
    'Updateby20150707
    Dim Rng As Range
    Dim xInterval As Integer
    Dim xRows As Integer
    Dim xRowsCount As Integer
    Dim xNum1 As Integer
    Dim xNum2 As Integer
    Dim WorkRng As Range
    Dim xWs As Worksheet
    xTitleId = "KutoolsforExcel"
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
    xRowsCount = WorkRng.Rows.Count
    xInterval = Application.InputBox("Enter row interval. ", xTitleId, 1, Type:=1)
    xRows = Application.InputBox("How many rows to insert at each interval? ", xTitleId, 1, Type:=1)
    xNum1 = WorkRng.Row + xInterval
    xNum2 = xRows + xInterval
    Set xWs = WorkRng.Parent
    For i = 1 To Int(xRowsCount / xInterval)
    xWs.Range(xWs.Cells(xNum1, WorkRng.Column), xWs.Cells(xNum1 + xRows - 1, WorkRng.Column)).Select
    Application.Selection.EntireRow.Insert
    xNum1 = xNum1 + xNum2
    Next
    End Sub"