Can anyone explain to me how this code works? I found it in an article.
Does it copy and paste rows from columns A to C based on value in cell D or does it duplicate it another way? I want something like this except I want to insert rows and only copy columns A and B. But if I don't know how to change this code so that column C also shifts down.![]()
Sub CopyData() Dim xRow As Long Dim VInSertNum As Variant xRow = 1 Application.ScreenUpdating = False Do While (Cells(xRow, "A") <> "") VInSertNum = Cells(xRow, "D") If ((VInSertNum > 1) And IsNumeric(VInSertNum)) Then Range(Cells(xRow, "A"), Cells(xRow, "D")).Copy Range(Cells(xRow + 1, "A"), Cells(xRow + VInSertNum - 1, "D")).Select Selection.Insert Shift:=xlDown xRow = xRow + VInSertNum - 1 End If xRow = xRow + 1 Loop Application.ScreenUpdating = False End Sub
Bookmarks