我在下面的代码中遇到了问题。 在第130行,我需要插入等于J中的值的空行。 代码现在插入等于J的空白行但是从行J开始。我需要从行k开始然后插入空白行J.如何定义起始行和空行数?
70 j = ws1.Cells(ws1.Rows.Count, "E").End(xlUp).Row
80 k = 2
90 x = 1
100 Do While x < j
110 With ws2
120 If j > 0 Then
'Insert J number of rows starting on row = k
130 .Rows(j).Resize(LastRow).Insert
140 For i = 2 To rngtocopy.Rows.Count
150 With ws2.Range("K" & k)
160 .Offset(0, 0).Value = rngtocopy(i, 1)
170 .Offset(0, 1).Value = rngtocopy(i, 2)
180 End With
190 k = k + 1
200 Next i
210 End If
220 End With
230 x = x + 1
240 Loop
答案 0 :(得分:0)
我不知道我是否理解你的问题,但试试这个:
Set ws1 = Sheets("Calc")
Set ws2 = Sheets("Dealer Orders")
LastRow = ws1.Cells(ws1.Rows.Count, "E").End(xlUp).Row
Set rngtocopy = ws1.Range("E2", ws1.Cells(LastRow, "F"))
For i = 1 To rngtocopy.Rows.Count
With ws2.Range("K2")
.Resize(, 2).Insert xlDown
.Offset(-1, 0).Value = rngtocopy(i, 1)
.Offset(-1, 1).Value = rngtocopy(i, 2)
End With
Next
这是不是你想要的? HTH。