简体   繁体   English

在所选单元格或行下方插入新行

[英]Insert new row below the selected cell or row

I have protected excel sheet.我已经保护了excel表。 The first row is at no.10 and all new rows are inserted below.第一行在 10 号,所有新行都插入下面。

I have put below code with command button to insert a new row at the bottom with same format and formula copied from above row.我在下面的代码中添加了命令按钮,以在底部插入一个新行,并从上面的行复制相同的格式和公式。 This works perfectly fine.这工作得很好。

ActiveSheet.Unprotect""
ActiveSheet.Range("A10").CurrentRegion.Offset(ActiveSheet.Range("A10").CurrentRegion.Rows.Count - 1).Resize(2).EntireRow.FillDown
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowDeletingRows:=True, AllowSorting:=True _
, AllowFiltering:=True
ActiveSheet.Protect "", True, True

But I cannot insert a new row in the middle of rows(with same format and formulas copied from above row).但是我不能在行中间插入新行(从上面的行复制相同的格式和公式)。

Can someone please edit my code so that I can insert a new row anywhere in the middle of rows wherever I want to insert by highlighting with mouse click.有人可以编辑我的代码,以便我可以通过单击鼠标突出显示在行中间的任何位置插入新行。

Of course the new row should be created below the highlighted cell and copied with same format and formulas as above row.当然,新行应在突出显示的单元格下方创建,并使用与上行相同的格式和公式进行复制。

Sub AddRow()  
    ActiveSheet.Unprotect "1234" 
    ActiveCell.Offset(1).EntireRow.Insert 
    ActiveCell.Offset(1).EntireRow.Cells.Locked = False 
    ActiveSheet.Protect "1234" 
End Sub  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM