PDA

View Full Version : Locking cells for editing.



shofil
11-08-2008, 10:16 AM
Hi! I have a shared workbook. I want to block some cells in a row if data is eneterd in the next row. For example: If I enter data in cell A13, I want cell A12 to be locked for editing. Please help on this.: pray2:

georgiboy
11-08-2008, 10:44 AM
Try this, it will need to go into the sheet module

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

x = Target.Row - 1
y = Target.Column

If Cells(x, y).Value <> "" Then
ActiveSheet.Unprotect
Cells(x, y).Locked = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End If

End Sub
Also you will need to have all the cells in question in the sheet unlocked and the sheet to be protected

hope this helps

georgiboy
11-08-2008, 11:00 AM
You could also add a password

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

x = Target.Row - 1
y = Target.Column

If Cells(x, y).Value <> "" Then
ActiveSheet.Unprotect Password:="password"
Cells(x, y).Locked = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="password"
End If

End Sub