Hi,
I am using code for sheet lock, but if selection goes (in this specific case) from A6 to A1 ( -> Range("A6:A1") <- ) it will keep unlocked file which is wrong.
If there is any kind of intersection with A6:AN35, it should not allow file to be unlocked. How to change this code into that?
I am using code for sheet lock, but if selection goes (in this specific case) from A6 to A1 ( -> Range("A6:A1") <- ) it will keep unlocked file which is wrong.
If there is any kind of intersection with A6:AN35, it should not allow file to be unlocked. How to change this code into that?
Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "A6:AN35" '<== change to suit
On Error GoTo ws_exit
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Call UnlockMe
End With
Else
With Target
Call LockMe
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub
Private Sub UnlockMe()
Sheet2.Unprotect "123"
End Sub
Private Sub LockMe()
Sheet2.Protect "123"
End Sub