M
MIke
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
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