Conditional Format Lock Cell

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,665
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Is there any way to lock a cell if it has a certain value?
 
As a result of an "if" formula.
So in essence, if the formula is positive, the user will not be permitted to edit the cell ... it's locked. If negative, the user can edit the cell ... unlocked.
 
Upvote 0
Try an event macro > right click sheet tab > select view code > paste in the below.

If A1 formula returns 10 then the cell is locked.

Code:
Private Sub Worksheet_Calculate()
Dim Rng As Range
Set Rng = Range("A1")

    Select Case Rng
        Case Is = 10
            Rng.Locked = True
        Case Else
            Rng.Locked = False
    End Select
End Sub

HTH

VBA Noob
 
Upvote 0
Since there is a formula in the cell, what cell should be locked? I assume the cell with formula is already locked. Am I wrong? Provide specifics.

lenze
 
Upvote 0
Hi Lenze,

This is a normally unlocked cell (A1) allowing a user to enter information. However, if a certain value is encountered in another worksheet cell (B2), the user no longer should be permitted to edit (enter information) in the unlocked field (A1). That value when encountered in B2 needs to lock the cell A1 to prevent editting.

So, formula in cell A1 is if(b2="NO","","ok"). So, if locking a cell was available through conditional formatting, I would apply something like ... if A1 = "NO" then (Lock cell)

Hmmm?
 
Upvote 0
I still don't get it. If you have
=IF(B2="NO","","OK")
in A1, why can someone enter info in A1?

lenze
 
Upvote 0
I think now maybe I'm getting confused. :-)

I believe the only reason why I want to lock the cell is to prevent a) the user selecting it, and b) overwriting what the formula has defined.

If the formula in A1 assigns B2 a value of NO, I don't want the user to be able to select and overwrite the value assigned by the formula. However, with any other value, the user is permitted to select and change.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top