代码这样改:
Private Sub CommandButton1_Click()
ActiveSheet.Unprotect Password:=2
a = Selection.Row
Rows(a & ":" & a).Select
Selection.Copy
selecttion.Insert shift:=xlDown
ActiveSheet.Protect Password:=2
End Sub
Private Sub CommandButton2_Click()
ActiveSheet.Unprotect Password:=2
selecttion.EntireRow.Delete
ActiveSheet.Protect Password:=2
End Sub
工作表被保护后,当然不能插入行或删除行,当你点击 命令按钮时,运行到插入行或删除行这句语句时,就出错了
在设置保护的时候把 插入行插入列选上 就可以运行宏了