Conditional cell lock

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to conditionally lock a cell in a protected worksheet. Here is the example: I have a formula in cell to do a calculation. I want to lock that cell so that the formula cannot be changed. However if a user checks a forms box returning a "true" in the referenced cell, I want to be able to override the formula. I see how to do this to conditionally format font , border, or patterns, but not cell lock. Can this be done?
 
Mike,

You could set the locked property of the formula cell based on the status of
the referenced cell. You can't change the locked status of a cell in a
protected sheet unless the sheet has been protected in code with the
Userinterfaceonly property set to True. Userinterfaceonly allows you to
change a protected sheet with code, although the user still can't. The
Userinterfaceonly setting is lost when the workbook is closed, so you need
to do it in code when the workbook is opened. Below is an example of these
two steps.

Private Sub Workbook_Open() ' insert this in the ThisWorkbook module,
not a regular module
Sheet1.Protect password:="drowsapp", userinterfaceonly:=True
End Sub

Sub test2()
If Sheet1.Range("A1") = True Then
Sheet1.Range("A2").Locked = False
Else
Sheet1.Range("A2").Locked = True
End If
End Sub

hth,

Doug

Mike Rosenberg said:
I would like to conditionally lock a cell in a protected worksheet. Here
is the example: I have a formula in cell to do a calculation. I want to
lock that cell so that the formula cannot be changed. However if a user
checks a forms box returning a "true" in the referenced cell, I want to be
able to override the formula. I see how to do this to conditionally format
font , border, or patterns, but not cell lock. Can this be done?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top