LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default lock cells based on formula

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



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lock a formula to a column of cells dragons_lair Excel Worksheet Functions 3 May 21st 09 02:53 AM
lock cells based on interior color MIke Excel Discussion (Misc queries) 4 December 27th 07 08:59 PM
lock cells based on formula result MIke Excel Discussion (Misc queries) 1 October 26th 07 03:24 PM
Lock formula cells? EllenM Excel Discussion (Misc queries) 5 June 20th 07 09:04 PM
lock only formula cells without protecting sheet - leave open BLANK JUNK MAIL RECEIVED - CREATE RULE Excel Programming 0 May 12th 06 03:53 AM


All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"