Lock cell if based on value of corresponding cell

  • Thread starter Thread starter Kashyap
  • Start date Start date
K

Kashyap

Hi, I was tring to lock cell if value of corresponding cell is error
If value B3:B20 is error lock corresponding cells in ColumnE, F & H


OR
unlock cell if value of corresponding cell is >0

If value B3:B20 is >0 unlock corresponding cells in ColumnE, F & H
 
Putting this module into the individula sheet in the VBA editor will lock or
unlock the cells everytime the sheet is changed.

Sub Worksheet_Change(ByVal target As Range)

ActiveSheet.Unprotect
For B = 3 To 20
If IsError(Cells(B, 2)) Then
Cells(B, 5).Locked = True
Cells(B, 6).Locked = True
Cells(B, 8).Locked = True
Else
If Cells(B, 2) > 0 Then
Cells(B, 5).Locked = False
Cells(B, 6).Locked = False
Cells(B, 5).Locked = False
End If
End If
Next B
ActiveSheet.Protect
End Sub


or you could tie this same routine to a button if you only want to run it on
demand.
 
Back
Top