Lock cell in Excel worksheet with VB
Solved/Closed
MartynP
Posts
5
Registration date
Thursday 13 November 2014
Status
Member
Last seen
17 March 2015
-
13 Nov 2014 à 09:34
Martynp - 19 Nov 2014 à 08:38
Martynp - 19 Nov 2014 à 08:38
Related:
- Lock cell in Excel worksheet with VB
- Transfer data from one excel worksheet to another automatically - Guide
- Excel mod apk for pc - Download - Spreadsheets
- Caps lock reversed - Guide
- Arrow keys not working in excel - Guide
- Vb net find last row in excel sheet - Guide
2 responses
rizvisa1
Posts
4478
Registration date
Thursday 28 January 2010
Status
Contributor
Last seen
5 May 2022
766
15 Nov 2014 à 06:47
15 Nov 2014 à 06:47
I have not really tested this one. But i think it should work for u
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rowId As Long
If (Intersect(Target, Range(Cells(1, "H"), Cells(1000, "H"))) Is Nothing) Then
Exit Sub
End If
ActiveSheet.Unprotect ("")
For Each Row In Target.Rows
rowId = Row.Row
Range(Cells(rowId, "A"), Cells(rowId, "H")).Locked = (Cells(rowId, "H") = "Y")
Next
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
MartynP
Posts
5
Registration date
Thursday 13 November 2014
Status
Member
Last seen
17 March 2015
17 Nov 2014 à 08:19
17 Nov 2014 à 08:19
Hi rizvisa1
I think I have sorted this, just going to do some testing.
Many Thanks
I think I have sorted this, just going to do some testing.
Many Thanks
rizvisa1
Posts
4478
Registration date
Thursday 28 January 2010
Status
Contributor
Last seen
5 May 2022
766
19 Nov 2014 à 06:54
19 Nov 2014 à 06:54
Works for me. Only thing that i can think of is that you may have "y" instead of "Y". in that case you can change the line
(Cells(rowId, "H") = "Y")
to
(UCase(Cells(rowId, "H")) = "Y")
(Cells(rowId, "H") = "Y")
to
(UCase(Cells(rowId, "H")) = "Y")
17 Nov 2014 à 06:29
Thanks