以下适用于插入新行,但我想 将值添加到A,B,C和D列中的新行。相同的值 对于每个新插入的行。 A =“SPL”B =“检查”C =的值 它上面的细胞。 D =“转账”我很乐意这样做 融入循环。
Range("A4", Range("A4").End(xlDown)).Select
For Each MyCell In Selection
If MyCell.Value <> "" Then
MyCell.Offset(1, 0).EntireRow.Insert
End If
Next MyCell
答案 0 :(得分:2)
在您插入包含内容的行时,最好从下到上工作:
Sub Tester()
Dim MyCell As Range, rng As Range, x As Long
Set rng = Range("A4", Range("A4").End(xlDown))
For x = rng.Count To 1 Step -1
With rng.Cells(x)
If .Value <> "" Then
.Offset(1, 0).EntireRow.Insert
.Offset(1, 0).Resize(1, 4).Value = Array("a", "b", "c", "d")
End If
End With
Next x
End Sub