Locking cell values dynamically
By rose | January 6, 2009
Thanks
Doug
So, for example if column a was the cell asking if people were attending or not, and columns b - e were columns containing various data eg name, contact details, payment status etc. If column a is set to "no" - ie the person is not attending, I would like the columns b - e locked, and unable to be edited. If however column A is set to "yes" and the person is due to attend, I would like columns b - e to be editable. I also need to be able to change column a from yes to no and back again freely.
I am running XL XP - so perhaps I can use sheet protection as you say...
Doug
lock the contents of a cell (ghosting out the option)
What do you mean by that, 'ghosting out the option'? Or do you just want to lock the cell? If it's wanting to change the format of a cell, you'll need VBA. If it's wanting to change what is displayed in a cell (for the most part) you can use formulas.
Post back with details. :)
Paste this into your specific sheet module:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 1 Then Exit Sub
Application.Run "YesNo"
End Sub
Now in a standard module, paste this in there:
Sub YesNo()
Dim r As Range, s As Range
Set r = Range("A2", Range("A65536").End(xlUp))
For Each s In r
If s.Value = "Yes" Then
Range(s.Offset(0, 1), s.Offset(0, 4)).Locked = True
Else: Range(s.Offset(0, 1), s.Offset(0, 4)).Locked = False
End If
Next s
End Sub
Works pretty good for me, only locks B:E (of that same row) for each Yes/No.
| ||||||||
| ||||||||
| ||||||||
| Yes/No | Name | M/F | Eyes | Hair | ||||
| Yes | Doug | M | Blue | Brown | ||||
| Yes | Zack | M | Green | Brown | ||||
| ||||||||
[HtmlMaker 2.42] To see the formula in the cells just click on the cells hyperlink or click the Name box
PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.
The cells in col A are Data Validation/List of "Yes,No" only. Code only allows for the text "Yes", so it can be anything else. HTH
1)
I have set up conditional formatting, to format the text to grey for any persons who have chosen not to attend the function. This is done via a drop down menu and choosing "no". This works well and is not a problem. The second part is where I need the help
2)
I want to fix it so that once "no" has been chosen in the attendance column, no other values for that individual can be changed such as the "paid" column for example. So in essence I want to lock the row, dependant on the value of one column within that cell. I also need to be able to change the attendance cell back to yes incase anyone changes their mind
Am I going about this the right way, or is there a better way to solve the problem?
Just to clarify the individuals are listed in rows, and the values are listed in columns along the top.
Thanks
Doug
Thanks for the advice. It took a bit of 'tinkering' with to get it to work exactly the way I needed it to, but I have tinkered, and it does.
Many thanks
Doug
The other was the wife's account. Don't know what happened there. :confused: Before I realized it..
And what version of excel are you running? Are you wanting to restrict access to locked cells? This is a breeze in xl XP with sheet protection.
#If you have any other info about this subject , Please add it free.# |
Topics: enart.xn--fiqs8sjn5by0n.com | edit
