Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 58
Default How can you lock cell conditionally


How can you conditionally (using the condition format) lock the cell?

Thank you in advance!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default How can you lock cell conditionally

Not with conditional formatting. What cell do you want to protect based on
what condtion? This could be done with VBA if you provide more detail.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)





"SAM SEBAIHI" wrote in message
...

How can you conditionally (using the condition format) lock the cell?

Thank you in advance!


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default How can you lock cell conditionally

Hi Sam,

This seems to work...

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Columns(1)) Is Nothing Then
Me.Unprotect "sam"
Dim rngCell As Range
For Each rngCell In Intersect(Target, Columns(1))
If rngCell.Value = "" Then
rngCell.Offset(0, 1).Locked = True
Else: rngCell.Offset(0, 1).Locked = False
End If
Next rngCell
Me.Protect "sam"
End If
End Sub


I've used "sam" as the worksheet protection password, so change that to
match the password you are using, or delete it if you are not using
one.

To get the code in place...

1. Copy it
2. Right click the worksheet's tab then select "View Code" from the
popup menu
3. Paste the code into the code module that appears
4. Get out of the Visual Basic Editor by either pressing Alt + F11 or
going File|Close and Return to Microsoft Excel.

The Security setting of the workbook will need to be "Medium" and
"Enable Macros" on the "Security Warning" dialog will have to be
selected when the workbook opens.

If this is not already the case then go Tools|Macro|Security... click
on "Medium"|OK|Close|Open|click "Enable Macros" on the "Security
Warning" dialog|OK.

Ken Johnson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 58
Default How can you lock cell conditionally

Thank you chip,

I need for example to lock cell B1 if cell A1 is empty, same with B2 to be
locked if A2 is empty. If A3 is not empty, then I don't want to have cell B3
to be locked...etc..
thank you in advance.

==================================================
"Chip Pearson" wrote in message
...
Not with conditional formatting. What cell do you want to protect based on
what condtion? This could be done with VBA if you provide more detail.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)





"SAM SEBAIHI" wrote in message
...

How can you conditionally (using the condition format) lock the cell?

Thank you in advance!



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 58
Default How can you lock cell conditionally

Thank you so much Ken :-)
--------------------------------------------------------------------------------
Sam Sebaihi Faculty Western International University Associate Programs "Ken
Johnson" wrote in message
ups.com...
Hi Sam,

This seems to work...

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Columns(1)) Is Nothing Then
Me.Unprotect "sam"
Dim rngCell As Range
For Each rngCell In Intersect(Target, Columns(1))
If rngCell.Value = "" Then
rngCell.Offset(0, 1).Locked = True
Else: rngCell.Offset(0, 1).Locked = False
End If
Next rngCell
Me.Protect "sam"
End If
End Sub


I've used "sam" as the worksheet protection password, so change that to
match the password you are using, or delete it if you are not using
one.

To get the code in place...

1. Copy it
2. Right click the worksheet's tab then select "View Code" from the
popup menu
3. Paste the code into the code module that appears
4. Get out of the Visual Basic Editor by either pressing Alt + F11 or
going File|Close and Return to Microsoft Excel.

The Security setting of the workbook will need to be "Medium" and
"Enable Macros" on the "Security Warning" dialog will have to be
selected when the workbook opens.

If this is not already the case then go Tools|Macro|Security... click
on "Medium"|OK|Close|Open|click "Enable Macros" on the "Security
Warning" dialog|OK.

Ken Johnson





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default How can you lock cell conditionally

You're welcome Sam.
Thanks for the feedback.

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
Using an offset formula for the reference in a relative reference Cuda Excel Worksheet Functions 6 November 15th 06 05:12 PM
Help with this conditional IF statement C-Dawg Excel Discussion (Misc queries) 3 May 15th 06 06:01 PM
Urgent date/scheduling calc needed jct Excel Worksheet Functions 3 February 24th 06 01:36 AM
cell color index comparison MINAL ZUNKE New Users to Excel 1 June 30th 05 07:11 AM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM


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