G'day everyone ~ Thanks again for your assistance
I am trying to write some code that will allow me to lock cells after data has been entered.
What i have in my example code below locks cell b1. What i would like is to lock a range of cells after a user has entered some information.
eg user enters data in cells A1:F1 and then these cells lock. The next user enters data into A2:F2 and thes cells then lock and the next users enters data into A3:F3 and these cells then lock etc etc etc.
This is what I have at the moment:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Answ, Rng As Range
Application.ScreenUpdating = False
Set Rng = Application.Intersect(Target, Range("b1"))
If Target.Cells.Count > 1 Then Exit Sub
If Not Rng Is Nothing Then
Answ = MsgBox("This cell will now be locked.", vbOKCancel, "Confirm Change")
If Answ <> vbOK Then
Application.EnableEvents = False
Target.ClearContents 'clear contents if cancel is pressed
Application.EnableEvents = True
Exit Sub
End If
ActiveSheet.Unprotect "1"
Target.Locked = True
ActiveSheet.Protect Password:="1", DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
Application.ScreenUpdating = True
End Sub
I am trying to write some code that will allow me to lock cells after data has been entered.
What i have in my example code below locks cell b1. What i would like is to lock a range of cells after a user has entered some information.
eg user enters data in cells A1:F1 and then these cells lock. The next user enters data into A2:F2 and thes cells then lock and the next users enters data into A3:F3 and these cells then lock etc etc etc.
This is what I have at the moment:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Answ, Rng As Range
Application.ScreenUpdating = False
Set Rng = Application.Intersect(Target, Range("b1"))
If Target.Cells.Count > 1 Then Exit Sub
If Not Rng Is Nothing Then
Answ = MsgBox("This cell will now be locked.", vbOKCancel, "Confirm Change")
If Answ <> vbOK Then
Application.EnableEvents = False
Target.ClearContents 'clear contents if cancel is pressed
Application.EnableEvents = True
Exit Sub
End If
ActiveSheet.Unprotect "1"
Target.Locked = True
ActiveSheet.Protect Password:="1", DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
Application.ScreenUpdating = True
End Sub