Search code examples
excelfor-looplarge-datavba

Adding 10 rows between each row in my original table in Excel VBA


I have a table with data where I want to insert exactly 20 rows between each row of my original table. I have tried running nested for loops to add each row per loop and to hop onto the next "original" row on my table to add another 20 rows below it. However, this takes forever since I have over 2000 rows on my spreadsheet. Is there any other way to do this? Any vba code I could use for this?


Solution

  • Try this:

    Sub AddRows()
        ScreenUpdating = False
    
        With ActiveSheet
            lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
        End With
    
        Dim AddRows As Integer: AddRows = 10
    
        Dim i As Integer: i = lastrow
    
        Do While i <> 1
            Rows(i & ":" & i + AddRows - 1).Insert
            i = i - 1
        Loop
    
        ScreenUpdating = True
    End Sub