Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default MACROS: Protect a cell depending on the value of another cell

How can create a macro to protect a cell depending on the value of another
cell.
Ex: If A2<0 then I want A3 to be locked for editing.

Thanks for your help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default MACROS: Protect a cell depending on the value of another cell

frenchflo wrote:
How can create a macro to protect a cell depending on the value of another
cell.
Ex: If A2<0 then I want A3 to be locked for editing.

Thanks for your help.


If Range("A2").Value < 0 Then
ActiveSheet.Unprotect "your password here"
Range("A3").Locked = True
ActiveSheet.Protect "your password here"
End If

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default MACROS: Protect a cell depending on the value of another cell

Thanks for your quick answer.
But my worsheet needs to stay protected. Certain cells are already locked
and need to stay like that. So if I use your codes wont my worsheet be
unprotected if A20?

"Ken Johnson" wrote:

frenchflo wrote:
How can create a macro to protect a cell depending on the value of another
cell.
Ex: If A2<0 then I want A3 to be locked for editing.

Thanks for your help.


If Range("A2").Value < 0 Then
ActiveSheet.Unprotect "your password here"
Range("A3").Locked = True
ActiveSheet.Protect "your password here"
End If

Ken Johnson


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default MACROS: Protect a cell depending on the value of another cell

frenchflo wrote:
Thanks for your quick answer.
But my worsheet needs to stay protected. Certain cells are already locked
and need to stay like that. So if I use your codes wont my worsheet be
unprotected if A20?

"Ken Johnson" wrote:

frenchflo wrote:
How can create a macro to protect a cell depending on the value of another
cell.
Ex: If A2<0 then I want A3 to be locked for editing.

Thanks for your help.


If Range("A2").Value < 0 Then
ActiveSheet.Unprotect "your password here"
Range("A3").Locked = True
ActiveSheet.Protect "your password here"
End If


Hi,
If A20 then the code does nothing, it just skips to what ever code you
put after the End If statement, and your sheet remains protected, and
A3 remains unlocked if it was already unlocked.

Ken Johnson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default MACROS: Protect a cell depending on the value of another cell

Hi,
If you are wanting the macro to run automatically you could try this
code in the worksheet code module.
Copy the code then right click the sheet tab and select "View code"
from the popup menu. Paste the code into the code module that then
appears. Then press Alt + F11 to get out of the VBA Editor.
Don't forget to edit the password.

Private Sub Worksheet_Calculate()
Me.Unprotect "your password"
If Range("A2").Value < 0 Then
Range("A3").Locked = True
Else: Range("A3").Locked = False
End If
Me.Protect "your password"
End Sub

Ken Johnson

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
Macros to protect worksheet and prevent locked cell selection Excel Enthusiastic[_2_] Excel Discussion (Misc queries) 1 April 23rd 07 09:44 AM
EXCEL: Protect a cell depending on another cell value frenchflo Excel Worksheet Functions 1 October 11th 06 05:36 PM
How can i change cell colour depending on month of date in cell? andy75 Excel Discussion (Misc queries) 2 January 6th 06 07:46 AM
How do I change the color of a cell depending on the result of the function in that cell Mo Childs[_2_] Excel Programming 4 November 1st 05 09:30 PM
Automated cell copy depending on cell content? Joachim Fabini Excel Programming 5 November 20th 03 07:54 AM


All times are GMT +1. The time now is 08:27 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"