PDA

View Full Version : Please help me in this VBA



Esmatullah
12-11-2012, 04:39 AM
Hi dear friends!
How i can edit this macro code of automatic cell locking that don't lock when i double click for editing a cell in range and exit without editing.

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B7:D9")) Is Nothing Then Exit Sub
ActiveSheet.Unprotect Password:="Password"
Target.Locked = True
ActiveSheet.Protect Password:="Password"
End Sub

Kenneth Hobs
12-11-2012, 06:50 AM
That makes no sense. Your code is only triggered if a cell in the range is changed. Either you want protection from edits, or you don't.

That is the same code from your other thread. If that thread relates, you should include a link to the other thread. It is fine to post separate questions if they are separate.

When using Protect, use the option UserInterfaceOnly=True so that your code can edit protected cells without the need for UnProtect. I usually add that in ThisWorkbook's Open event.