I have been looking for a code to lock all the cells in a sheet but one and I found this code:
Worksheets("SW").Range("D2").Locked = False
Worksheets("SW").Protect UserInterfaceOnly:=True
it really worked fine until I saved it and closed/opened the file again, then any macros I had were run.
I guess it is because in that sheet I have different macros and also I have the macro that runs when a cell is changed:
Private Sub Worksheet_Change(ByVal Target As Range)
Do you have any idea how to make it work?
One more thing, this workbook it will be shared, so I don’t know that will affect the macros.
sorry maybe I was too ambiguous.
Yes I want to prevent others to change de value of the cells.
I want that just one cell could be changed so all the others are changing with the macros.
Thanks again for all your help
PS: yes Ahmad Al-Mutawa, I want to be impossible to chang the sheet even after the project being saved, closed and opened.
If you need more info just tell me I’ll try to be more specific.
Does your file have any macros doing other operations than this lock unlock code you are trying to achieve?
If so I suggest you having a code in vba. Otherwise you can simply lock the sheets to prevent users from changing somethings or anytime at all without a code.
do you think this could be better for you than a [code][1]?
[ http://office.microsoft.com/en-us/excel-help/lock-or-unlock-specific-areas-of-a-protected-worksheet-HA010096837.aspx ][1]
Out of curiosity: BY ANY CHANCE are you having an issue not knowing where and how to trigger this code piece?
Edited code:-
Your comment is not clear, nonethless I believe you want to use a macro.
Assuming you want to protect/lock or unprotect/unlock Sheet1, please try the following. :-
Add this code in Workbook open event in thisworkbook:-
Next add the following in your module. And call it after you finish running your macro.