VBA Excel - Insert row below with same format including borders and frames

前端 未结 4 1967
忘了有多久
忘了有多久 2021-02-10 05:53

I want to build a macro that inserts a row below the selected cell with the same format. This is the code I have so far:

Public Sub insertRowBelow()
ActiveCell.         


        
4条回答
  •  再見小時候
    2021-02-10 06:44

    Private Sub cmdInsertRow_Click()
    
        Dim lRow As Long
        Dim lRsp As Long
        On Error Resume Next
    
        lRow = Selection.Row()
        lRsp = MsgBox("Insert New row above " & lRow & "?", _
                vbQuestion + vbYesNo)
        If lRsp <> vbYes Then Exit Sub
    
        Rows(lRow).Select
        Selection.Copy
        Rows(lRow + 1).Select
        Selection.Insert Shift:=xlDown
        Application.CutCopyMode = False
    
       'Paste formulas and conditional formatting in new row created
        Rows(lRow).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone
    
    End Sub
    

    This is what I use. Tested and working,

    Thanks,

提交回复
热议问题