[英]Hello, I am trying to lock the cells in an excel sheet based on the values in other sheet of the excel
I have tried various codes that seem to work perfectly for others but not in my case. 我尝试了各种代码,这些代码似乎对其他人而言非常有效,但就我而言,并非如此。 Before i write any code the sheet, all the cells in my sheet appear as Locked anyways.
在我向工作表编写任何代码之前,工作表中的所有单元格始终显示为“已锁定”。 I am stuck here and do not know what can be done here.
我被困在这里,不知道可以在这里做什么。
I tried this code but nothing seems to be locked,i can still do whatever i want in the sheet. 我尝试了这段代码,但似乎什么都没有锁定,我仍然可以做我想做的任何事情。
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1") = "Accepting" Then
Range("B1:B4").Locked = False
ElseIf Range("A1") = "Refusing" Then
Range("B1:B4").Locked = True
End If
End Sub
Locking a range will have no effect unless the sheet is also protected. 除非还保护了工作表,否则锁定范围将无效。
For instance Range("B1:B4").Locked = True
won't work until you do YourWorksheet.Protect
. 例如,
Range("B1:B4").Locked = True
在您执行YourWorksheet.Protect
之前不会YourWorksheet.Protect
。 You can unprotect it after by doing YourWorksheet.Unprotect
. 您可以在执行
YourWorksheet.Unprotect
之后取消保护它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.