• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Conditional Cell Lock/Unlock

novice007

New Member
Hi team,


I have two cells, A1 and B1. If cell A1 value is "TRUE", I want to disable/lock cell B1, so that it cannot be changed at all.


Is there a formula that can perform this? I am trying to avoid macros, but if necessary I will have to use them.
 
Hi, novice007!


Copy and paste the following code in your sheet VBA code section:

-----

[pre]
Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$A$1" Then Exit Sub
With ActiveSheet
.Unprotect
.Range("B1").Locked = (Range("A1").Value = True)
.Protect
End With
End Sub
[/pre]
-----


Remember to protect the worksheet in order to work properly first time. Adjust protection and unprotection statements if password is required.


Regards!
 
Back
Top