偏移函数传统上用于单元格,但我想用它来复制和粘贴整行。如何对整行使用偏移函数?这是我的代码,然而,它不起作用。谢谢。
Sub Macro()
Rows("2:2").Select
Selection.Copy
Offset(1, 0).Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub
答案 0 :(得分:3)
尽可能避免选择。
Sub Macro()
Dim r As Long
Application.ScreenUpdating = False
For r = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
With Cells(r, 1).EntireRow
.Copy
.Resize(2).Offset(1, 0).Insert Shift:=xlDown
End With
Cells(r + 1, "S").Value = DateAdd("m", 1, Cells(r, "S"))
Cells(r + 2, "S").Value = DateAdd("m", 2, Cells(r, "S"))
Next r
Application.ScreenUpdating = True
End Sub