[英]Excel - How to conditionally lock and unlock a particular cell using VBA.
Title says it all. 标题说明了一切。 Any insight here? 这里有什么见识吗? This code is most definitely not working: 此代码绝对不起作用:
Sub MrFreeze(ByVal Target As Range)
Dim cCell As Range
Dim wksInput As Worksheet
Set wksInput = Worksheets("Input")
Set cCell = wksInput.Range("D14")
If cCell.Value = "Yes" Then
ActiveSheet.Unprotect Password = "password"
Else
ActiveSheet.Protect Password = "password", DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
End Sub
Thank you in advance for any help! 预先感谢您的任何帮助!
If cell D14 contains Yes and the macro is run, the cell will be unlocked. 如果单元格D14包含“ 是”并且运行宏,则该单元格将被解锁。
If cell D14 does not contains Yes and the macro is run, the cell will be locked. 如果单元格D14不包含“ 是”并且运行宏,则该单元格将被锁定。
Sub MrFreeze()
Dim cCell As Range
Dim wksInput As Worksheet
Set wksInput = Worksheets("Input")
Set cCell = wksInput.Range("D14")
If cCell.Value = "Yes" Then
ActiveSheet.Unprotect Password = "password"
cCell.Locked = False
ActiveSheet.Unprotect Password = "password"
Else
ActiveSheet.Unprotect Password = "password"
cCell.Locked = True
ActiveSheet.Protect Password = "password"
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.