好的,所以我完成了工作,并添加了我的代码来更改同一循环中的另一个列,我的最后一个挑战是查看我的Q列,其中包含所订购商品的数量,如果它是> 1然后复制整行,并将其粘贴到新插入的行中,但数量超过1。 实施例
Josh Smith Soda 1
John Doe Banana 3
John Doe Banana 3
John Doe Banana 3
Tony Brown Cake 1
需要成为
Sub prepLabels()
Dim i As Long
For i = 3 To Range("A2").End(xlDown).Row Step 1
If Cells(i, "Q") > 1 Then
ActiveCell.EntireRow.Select
Selection.Copy
Selection.Insert Shift:=xlDown
End If
End If
Next i
End Sub
到目前为止我的代码是:
function validateForm() {
var result = true;
var msg = "";
if (document.ExamEntry.name.value === "") {
msg = document.createTextNode("You Must Indicate Your Level");
document.getElementById('name-msg').appendChild(msg);
document.getElementById('name-msg').style.color = "red";
} else {
document.getElementById('name-msg').innerHTML = '';
}
}
但显然我失败了,因为我的第一行简单地复制了7次或者什么。
答案 0 :(得分:1)
插入行时,始终从底部开始并向顶部工作,以便插入的行不会与迭代计数冲突。
Sub prepLabels()
Dim i As Long, r As Long, lr As Long
With ActiveSheet 'define this worksheet properly!
lr = .Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 3 Step -1
For r = 2 To .Cells(i, "Q").Value2
.Cells(i + 1, 1).EntireRow.Insert
.Cells(i, 1).Resize(2, Columns.Count).FillDown
Next r
Next i
End With
End Sub