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

前端 未结 4 1982
忘了有多久
忘了有多久 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:41

    well, using the Macro record, and doing it manually, I ended up with this code .. which seems to work .. (although it's not a one liner like yours ;)

    lrow = Selection.Row()
    Rows(lrow).Select
    Selection.Copy
    Rows(lrow + 1).Select
    Selection.Insert Shift:=xlDown
    Application.CutCopyMode = False
    Selection.ClearContents
    

    (I put the ClearContents in there because you indicated you wanted format, and I'm assuming you didn't want the data ;) )

提交回复
热议问题