首页 文章

在工作表中的最后一行之后插入新行,并从上面的单元格复制格式和公式

提问于
浏览
1

我正在寻找一个VBA宏脚本,它将找到工作表中的最后一行,然后在它下面插入一个新行,只复制上面一行中没有文本的格式和公式 . 到目前为止,我已经能够找到最后一行并复制上面的整个单元格,包括文本,但是却无法弄清楚最后一部分没有携带文本 .

我想知道是否有一些方法可以在工作表末尾创建新行的宏,然后在该行中重新创建公式?

任何帮助是极大的赞赏!

到目前为止,这是我的工作:

Sub New_Formatted_Row_With_Formula

 'Locates Last Cell
  Cells(Rows.Count, 1).End(xlUp).Offset(1,0).Select
 'Inserts Row Below
  Rows(Selection.Row).Insert shift:=xlDown

End Sub

1 回答

  • 1
    Sub New_Formatted_Row_With_Formula()
    Dim rActive As Range
    
    Set rActive = ActiveCell
    
    Application.ScreenUpdating = False
    
    With Cells(Rows.Count, "A").End(xlUp)
        .EntireRow.Copy
        With .Offset(1, 0).EntireRow
            .PasteSpecial xlPasteFormats
            .PasteSpecial xlPasteFormulas
            On Error Resume Next
                .SpecialCells(xlCellTypeConstants).ClearContents
            On Error GoTo 0
        End With
    End With
    
    rActive.Select
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
    End Sub
    

相关问题