我有一个包含 242 行的工作表。我想在每个现有的下面创建一个新行。相反,我的代码在第 1 行下方创建了 242 行。我整个下午都在 Google 和 Stack Overflow 上,尝试了各种想法,但遇到了同样的问题。这是我的代码:
Function rws() As Integer
rws = (Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).row)
End Function
Sub InsRws()
Dim rng As Range
Dim row As Range
Set rng = Range("A1:A" & rws - 1)
For Each row In rng.Rows
Rows.Select
ActiveCell.Offset(1).EntireRow.Insert
Next row
End Sub
最佳答案
也许这会有所帮助
Function rws() As Integer
rws = (Cells(rows.Count, "A").End(xlUp).Offset(1, 0).row)
End Function
Sub InsRws()
Dim rowCount As Integer
Dim i As Integer
rowCount = rws
For i = 1 To rowCount
Range("A" + CStr(2 * i - 1)).Select
ActiveCell.Offset(1).EntireRow.Insert
Next
End Sub
关于excel - MS Excel For Each Loop : Insert Rows,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16001937/