通过VBA复制公式时,防止Excel单元受到保护

我正在使用VBA代码在Excel 2016工作表中插入新行,然后将公式从上面的行复制到新行,以便我不必手动插入它们。 不幸的是公式插入的单元格在复制公式后受到保护。 这带来了一个缺点,如果我犯了一个错误,我不能删除新的一行。 这是我的代码。

Private Sub Worksheet_Change(ByVal Target As Range) ' Disable events to prevent that insertion of the row triggers a new Worksheet_Change ' event. Without this action the worksheet would be in an endles loop. Application.EnableEvents = False If Target.Column = 1 Then If Cells(Target.Row + 2, 1).Value = "end" Then Cells(Target.Row + 1, 1).EntireRow.Insert End If End If ' Copy formulas Cells(Target.Row - 1, 2).Copy (Cells(Target.Row, 2)) Cells(Target.Row - 1, 5).Copy (Cells(Target.Row, 5)) Cells(Target.Row - 1, 2).Unprotect Cells(Target.Row - 2, 5).Unprotect ' Reactivate events so that the worksheet can react to user changes. Application.EnableEvents = True End Sub 

正如你所看到的,我也试图解除细胞的保护,但这没有帮助。 我能做些什么来防止复制公式后这些细胞受到保护? 我正在尝试这个好几个小时,Google直到现在才回答我的问题。

谢谢你的帮助!