Forum Discussion

ushbar's avatar
ushbar
Copper Contributor
Oct 28, 2020
Solved

Macro/VBA code to duplicate every N-th row, N times

Hi,   I'm a newbie to VBA and macro so I need help with a script/code that can duplicate every 17th row, four number of times. This should be a loop.   I have attached a part of my dataset. I wan...
  • HansVogelaar's avatar
    Oct 28, 2020

    ushbar 

    Here is a macro:

    Sub InsertRows()
        Dim r As Long
        Dim m As Long
        Application.ScreenUpdating = False
        m = Range("A" & Rows.Count).End(xlUp).Row
        m = ((m - 1) \ 17) * 17 + 1
        For r = m To 18 Step -17
            Range("A" & r).EntireRow.Copy
            Range("A" & r + 1).Resize(4).EntireRow.Insert
        Next r
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    End Sub

Resources