Lock cells in Excel
Solved/Closed
MartynP
Posts
5
Registration date
Thursday November 13, 2014
Status
Member
Last seen
March 17, 2015
-
Nov 20, 2014 at 08:52 AM
MartynP - Nov 26, 2014 at 06:47 AM
MartynP - Nov 26, 2014 at 06:47 AM
Related:
- Lock cells in Excel
- Number to words in excel - Guide
- Caps lock reversed - Guide
- Gif in excel - Guide
- Marksheet in excel - Guide
- How to take screenshot in excel - Guide
2 responses
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Nov 22, 2014 at 07:17 AM
Nov 22, 2014 at 07:17 AM
It does not work because exit sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rowId As Long
'check in the area that was change contains at least one cell from M1:M1005 or R1:R1005
If (Intersect(Target, Union(Range(Cells(1, "M"), Cells(1005, "M")), Range(Cells(1, "R"), Cells(1005, "R")))) Is Nothing) Then
' no mactch, so nothing to do
Exit Sub
End If
'have some thing to so first unprotect sheet
ActiveSheet.Unprotect ("")
'for each row that have been modified, check
For Each Row In Target.Rows
rowId = Row.Row
'check lock/unlock cells A:M
Range(Cells(rowId, "A"), Cells(rowId, "M")).Locked = (UCase(Cells(rowId, "M")) = "Y")
'check lock/unlock cells N:R
Range(Cells(rowId, "N"), Cells(rowId, "R")).Locked = (UCase(Cells(rowId, "R")) = "Y")
Next
ActiveSheet.Protect ("")
End Sub