Lock cells in Excel
Solved/Closed
MartynP
Posts
5
Registration date
Thursday 13 November 2014
Status
Member
Last seen
17 March 2015
-
20 Nov 2014 à 08:52
MartynP - 26 Nov 2014 à 06:47
MartynP - 26 Nov 2014 à 06:47
Related:
- Lock cells in Excel
- Excel mod apk for pc - Download - Spreadsheets
- Caps lock reversed - Guide
- Excel cell color formula - Guide
- Count occurrences in excel - Guide
- Excel online macros - Guide
2 responses
rizvisa1
Posts
4478
Registration date
Thursday 28 January 2010
Status
Contributor
Last seen
5 May 2022
766
22 Nov 2014 à 07:17
22 Nov 2014 à 07:17
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
