#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default lock cell

Can anyone help me with the following code? I am trying to lock a row based
on the results of two formulas. If either one of the results are greater
then a certain value then the row will lock. The following code locks the
cell if the first condition is met but not the second. Is there another way
I could get it to check the second condition. Any help would be greatly
appreciated.

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 100 Or myCell.Offset(0, 2).Value 12.5 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

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default lock cell

What's in the second cell for one of the failing rows?

It looks like your code should work (well, to me anyway).

But I would move the .protect line under the ws_exit: line.

MIke wrote:

Can anyone help me with the following code? I am trying to lock a row based
on the results of two formulas. If either one of the results are greater
then a certain value then the row will lock. The following code locks the
cell if the first condition is met but not the second. Is there another way
I could get it to check the second condition. Any help would be greatly
appreciated.

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 100 Or myCell.Offset(0, 2).Value 12.5 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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default lock cell

Dave,
Do you mean the cell used for the second condition? If so, it has a formula
(o/p) in it. If the result exceeds 12.5 I need the row to lock. I have
plugged in samples exceeding the 12.5 and it doesnt lock. The row only locks
if I go over the first condition.

Basically, the sheet is set up to calculate the total in column O using
values in columns b to n. In Column P you input hrs worked and Column Q
calculates the number per hr.

Thanks for the help.

Mike

"Dave Peterson" wrote:

What's in the second cell for one of the failing rows?

It looks like your code should work (well, to me anyway).

But I would move the .protect line under the ws_exit: line.

MIke wrote:

Can anyone help me with the following code? I am trying to lock a row based
on the results of two formulas. If either one of the results are greater
then a certain value then the row will lock. The following code locks the
cell if the first condition is met but not the second. Is there another way
I could get it to check the second condition. Any help would be greatly
appreciated.

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 100 Or myCell.Offset(0, 2).Value 12.5 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


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default lock cell

Just a guess.

My bet is that you have a mistake in your layout.

What columns did you mean to check? Column O and the column 2 to its right
(column Q)???

When mycell is in column O, then myCell.Offset(0, 2) is in column Q.

But that's just a guess.

MIke wrote:

Dave,
Do you mean the cell used for the second condition? If so, it has a formula
(o/p) in it. If the result exceeds 12.5 I need the row to lock. I have
plugged in samples exceeding the 12.5 and it doesnt lock. The row only locks
if I go over the first condition.

Basically, the sheet is set up to calculate the total in column O using
values in columns b to n. In Column P you input hrs worked and Column Q
calculates the number per hr.

Thanks for the help.

Mike

"Dave Peterson" wrote:

What's in the second cell for one of the failing rows?

It looks like your code should work (well, to me anyway).

But I would move the .protect line under the ws_exit: line.

MIke wrote:

Can anyone help me with the following code? I am trying to lock a row based
on the results of two formulas. If either one of the results are greater
then a certain value then the row will lock. The following code locks the
cell if the first condition is met but not the second. Is there another way
I could get it to check the second condition. Any help would be greatly
appreciated.

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 100 Or myCell.Offset(0, 2).Value 12.5 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


--

Dave Peterson


--

Dave Peterson
  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default lock cell

Don,

I am a novice to visual basic. I used the calculation event originally
because I just wanted to monitor the initial event in Column O but forgot
about the requirement in Column Q. Could were I have it located be the
reason it is not working for me?

Thanks fo the help,
Mike



"Don Guillett" wrote:

I tested OK. Why use a calculation event which will fire with EACH
calculation. Why not a worksheet_change event that fires with col O or col Q

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"MIke" wrote in message
...
Can anyone help me with the following code? I am trying to lock a row
based
on the results of two formulas. If either one of the results are greater
then a certain value then the row will lock. The following code locks the
cell if the first condition is met but not the second. Is there another
way
I could get it to check the second condition. Any help would be greatly
appreciated.

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 100 Or myCell.Offset(0, 2).Value 12.5 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



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default lock cell


As has been pointed out, your code works. If desired, send a workbook to my
private email below along with complete instructions as to your desires.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"MIke" wrote in message
...
Don,

I am a novice to visual basic. I used the calculation event originally
because I just wanted to monitor the initial event in Column O but forgot
about the requirement in Column Q. Could were I have it located be the
reason it is not working for me?

Thanks fo the help,
Mike



"Don Guillett" wrote:

I tested OK. Why use a calculation event which will fire with EACH
calculation. Why not a worksheet_change event that fires with col O or
col Q

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"MIke" wrote in message
...
Can anyone help me with the following code? I am trying to lock a row
based
on the results of two formulas. If either one of the results are
greater
then a certain value then the row will lock. The following code locks
the
cell if the first condition is met but not the second. Is there
another
way
I could get it to check the second condition. Any help would be greatly
appreciated.

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 100 Or myCell.Offset(0, 2).Value 12.5 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




Reply
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
How to lock a cell value when values going into that cell keep changing... momentumtrader Excel Discussion (Misc queries) 5 April 22nd 07 11:56 PM
I have lock a wookbook but one cell does not want to lock it Mimi Excel Discussion (Misc queries) 2 January 21st 07 10:59 PM
I have lock a wookbook but one cell does not want to lock it Mimi Excel Discussion (Misc queries) 1 January 21st 07 09:44 AM
How to lock a cell Teethless mama Excel Worksheet Functions 0 November 30th 06 03:06 AM
Lock data in a cell a specific cell based on selection on other ce CrimsonPlague29 Excel Worksheet Functions 0 May 10th 06 11:06 AM


All times are GMT +1. The time now is 05:23 PM.

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

About Us

"It's about Microsoft Excel"