PC Review


Reply
Thread Tools Rate Thread

conditional lock format

 
 
Elfego Baca
Guest
Posts: n/a
 
      27th Mar 2007
I would like to lock a cell if a specific word or words is entered into
another cell and unlock it when any other words are entered.

For example I have a dropdown list in C3 that has the following items:
self, spouse, relative, friend, other. If one enters self or spouse
then C4 would be locked. If you enter Relative, Friend or other then C4
would be unlocked.
 
Reply With Quote
 
 
 
 
JE McGimpsey
Guest
Posts: n/a
 
      27th Mar 2007
One way:

Put this in your worksheet code module (right-click the worksheet tab
and choose View Code):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const csPWORD As String = "drowssap"
Dim sText As String
With Target
If .Count = 1 Then
If .Address(False, False) = "C3" Then
sText = LCase(.Text)
ActiveSheet.Unprotect Password:=csPWORD
Range("C4").Locked = _
(sText = "self") Or (sText = "spouse")
ActiveSheet.Protect Password:=csPWORD
End If
End If
End With
End Sub

Change the csPWORD password variable to suit.

In article <(E-Mail Removed)>,
Elfego Baca <(E-Mail Removed)> wrote:

> I would like to lock a cell if a specific word or words is entered into
> another cell and unlock it when any other words are entered.
>
> For example I have a dropdown list in C3 that has the following items:
> self, spouse, relative, friend, other. If one enters self or spouse
> then C4 would be locked. If you enter Relative, Friend or other then C4
> would be unlocked.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      27th Mar 2007
You could use an event macro that unprotects the worksheet, locks or unlocks the
cell and then reprotects the worksheet. The worksheet has to be protected for
the lockedness of the cell to have any impact.

If you want to try, rightclick on the worksheet tab that should have this
behavior and select view code. Then paste this into the code window that you
see:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myPWD As String

If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("C3")) Is Nothing Then
Exit Sub
End If

myPWD = "hi"

On Error GoTo ErrHandler:

Application.EnableEvents = False
Me.Unprotect Password:=myPWD
Select Case LCase(Target.Value)
Case Is = "", "self", "spouse"
With Target.Offset(1, 0)
.Value = ""
.Locked = True
End With
Case Else
With Target.Offset(1, 0)
.Value = ""
.Locked = False
End With
End Select

ErrHandler:
Me.Protect Password:=myPWD
Application.EnableEvents = True

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

You can read more about events at:
Chip Pearson's site:
http://www.cpearson.com/excel/events.htm

David McRitchie's site:
http://www.mvps.org/dmcritchie/excel/event.htm

Elfego Baca wrote:
>
> I would like to lock a cell if a specific word or words is entered into
> another cell and unlock it when any other words are entered.
>
> For example I have a dropdown list in C3 that has the following items:
> self, spouse, relative, friend, other. If one enters self or spouse
> then C4 would be locked. If you enter Relative, Friend or other then C4
> would be unlocked.


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lock range based on conditional format colour. fishy Microsoft Excel Misc 4 11th Sep 2009 02:39 PM
Conditional Format overwrighting previous conditional format davethewelder Microsoft Excel Programming 2 10th Apr 2008 05:01 PM
Lock cell formats (conditional format) Saintsman Microsoft Excel Worksheet Functions 1 8th Jan 2008 06:12 PM
Conditional Format To Lock Cell james@smooth-tech.com Microsoft Excel Misc 0 1st Nov 2007 05:20 PM
lock cell conditional format but not restrict data entry =?Utf-8?B?R0FN?= Microsoft Excel Worksheet Functions 1 18th Aug 2007 07:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:48 PM.