VBA row locking based on the value of a cell in that row
maipouri973
Posted messages
4
Registration date
Status
Member
Last intervention
-
maipouri973 Posted messages 4 Registration date Status Member Last intervention -
maipouri973 Posted messages 4 Registration date Status Member Last intervention -
Hello,
I am looking in VBA to lock a row if the cell in column A of that row is empty, and this should apply to each row in the sheet.
Thank you for your help.
I am looking in VBA to lock a row if the cell in column A of that row is empty, and this should apply to each row in the sheet.
Thank you for your help.
3 answers
-
Hello
there may be a solution with conditional formatting and two cell styles (locked and unlocked) -
Hello,
First, you need to protect the sheet.
After selecting the entire sheet, lock all cells (right-click, Format Cells > Protection > check "Locked").
Select column A, then unlock these cells (right-click, Format Cells > Protection > uncheck "Locked").
Tab Review > Protect > Protect the sheet (Allow users to select unlocked cells).
Place the following procedure in the sheet module:Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Application.Intersect(Columns("A"), Target) Is Nothing Then
ActiveSheet.Unprotect
If Target = "" Then
ActiveSheet.Range("B" & Target.Row).Resize(, Columns.Count - 1).Locked = True
Else
ActiveSheet.Range("B" & Target.Row).Resize(, Columns.Count - 1).Locked = False
End If
ActiveSheet.Protect
End If
End Sub
Best regards -