复制并粘贴variables行

我有一个macros在现有的数据行之间插入一些行:

Sub test() Dim j As Long, r As Range j = InputBox("No. of rows to be inserted?") Set r = Range("A3") Do Range(r.Offset(1, 0), r.Offset(j, 0)).EntireRow.Insert Set r = Cells(r.Row + j + 1, 1) If r.Offset(1, 0) = "" Then Exit Do Loop End Sub 

我真正需要做的是插入行'x'次的副本,而不是插入空白的。 谁能帮忙? 我提前道歉,因为我缺乏这方面的知识!

之前 – 修正

尝试这个

 Option Explicit Sub test() Dim j As Long Dim rng As Range, cell As Range Dim i As Long j = Application.InputBox("No. of rows to be inserted?", Type:=1) With Worksheets("REFS") '<-_| change "REFS" to your actual worksheet name i = 1 With .Range("D2", .Cells(.Rows.Count, "D").End(xlUp)) Do While i <= .Rows.Count With .Cells(i).EntireRow .Copy .Offset(1).Resize(j).Insert Shift:=xlDown Application.CutCopyMode = False End With i = i + j + 1 Loop End With End With End Sub 

我使用Application.InputBox()方法而不是VBA InputBox(),因为前者允许您强制用户input数据types(在示例中,Type:= 1强制数字input)