View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Pranav Vaidya Pranav Vaidya is offline
external usenet poster
 
Posts: 180
Default lock cells based on formula

Hi Mike,

I think you want the cells to be locked if any one condition is met. In that
case change

--
Pranav Vaidya
VBA Developer
PN, MH-India
If you think my answer is useful, please rate this post as an ANSWER!!

" If myCell.Value 8 Then" as

" If myCell.Value 8 OR myCell.Value 12 Then "

This change will check for both the conditions and will lock the cells if
either of the conditions are met. If you want both the conditions to be met,
then use AND instead of OR.

HTH,

"MIke" wrote:

I am trying to lock a range of cells based on two conditions. The first
condition is if the value in range (o7:037) 8. The second condition is if
the value in range Q7:Q37 12. If either of these condition are met I need
the corresponding range B:N to lock. I have the following code supplied to
me by Gord Dibben and it works great when evaluating one condition. He has
suggested using IF OR statements to evaluate the two conditions. I am not
that familiar with VBA code and I can not get the code to work. Can anyone
point me in the right direction?

Thanks, Mike

Private Sub Worksheet_Calculate()
Dim myCell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
ActiveSheet.Unprotect Password:="justme"
For Each myCell In Range("O7:O37")
If myCell.Value 8 Then
Range(myCell.Offset(0, -1), myCell.Offset(0, -13)).Locked = True
Else
Range(myCell.Offset(0, -1), myCell.Offset(0, -13)).Locked = False
End If
Next myCell
ActiveSheet.Protect Password:="justme"

ws_exit:
Application.EnableEvents = True
End Sub