在最后一个单元格下方而不是上方插入一行

Insert a row below the last cell and not above it

谁能帮我解决这个问题?

我正在尝试编写一个宏,它会在第 1 页最后一行包含文本的行之后插入一个包含文本的新行 - 请参见下图。

我希望宏在第 16 行之后的 PAGE 1 上插入一个新行,从而扩展第 1 页的边框或换句话说 下面.

但由于某种原因它只在上面插入一行。我需要它在下面插入。

这是代码-

Sub Macro5()


lastrow = Cells(Rows.Count, 1).End(xlUp).Row

Rows(lastrow).Select

Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove


End Sub

应该是个简单的任务,但不知为何,我找不到答案。

提前致谢。

只修改一行

lastrow = Cells(Rows.Count, 1).End(xlUp).Row + 1

插入行

  • 这将插入上面的行,然后将下面的行复制到上面的行并保持其格式。
  • 但不确定这是否会保留 Page 1 的最后一行。

代码

Option Explicit

Sub Macro5()
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Rows(LastRow).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
    Rows(LastRow + 1).Copy Rows(LastRow)
End Sub