Excel:允许用户删除包含受保护的单元格的行 [英] Excel: allow user to delete a row containing protected cells
问题描述
我需要保留一些包含公式的单元格,以防用户随意修改它们.为此,我保护了单元格并锁定了工作表.这样做将不允许用户删除这些行.
I need to preserve some cells, containing formulas, against the user to accidantally modify them. To do so, i protected the cell and locked the worksheet. Doing so, will disallow the user to delete those rows.
我该如何检测用户是否要删除整个行,并允许该操作不取决于该行是否包含受保护的单元格?
How can i do to detect if the user is deleting the WHOLE row, and allow this action not dependingly on if the row contains protected cells or not?
我想用VBA触发右键单击->删除行"操作,但是我找不到关于此的任何文档...
I thought to trigger the "right click -> delete row" action with VBA, but i can't find any documentation about this...
此外,我不想使用专用的蒙版或按钮来使UI复杂化...
Also, I don't want to use dedicated masks or buttons to don't complicate the UI...
推荐答案
您可以尝试以下简单代码:
You can try this simple code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address Like "$" & Target.Row & ":$" & Target.Row Then
ActiveSheet.Unprotect
Else
ActiveSheet.Protect
End If
End Sub
这篇关于Excel:允许用户删除包含受保护的单元格的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!