I am trying to write a code to Lock a cell with respect to target row. In example, If we select Priority column as Yes then Column Y1 should be locked. I am able to do that. The problem comes when I work on next row. If we select Priority column as Yes in the next row, then cell c3 gets locked but cell C2 gets unlocked, how to keep the cell C2 as locked
My code so far :
Private Sub Worksheet_Change(ByVal Target As Range)
If target.column = 1 then
If sheet1.range("A" & Target.Row).value = "Yes" then
sheet1.range("C" & target.row).locked = true
activesheet.protect password:="pass"
else
sheet1.range("C" & target.row).locked = false
End if
If we work on Row 2 then cell C2 gets locked, but if we work on Row 3 then cell C3 gets locked but C2 gets unlocked. How can we keep C2 as locked
