Hi,
I am looking for a way to lock lines of cells after data entry. I found the below code which works to lock one line.
Dim mRg As Range
Dim mStr As String
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("A12:O12"), Target) Is Nothing Then
Set mRg = Target.Item(1)
mStr = mRg.Value
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
On Error Resume Next
Set xRg = Intersect(Range("A12:O12"), Target)
If xRg Is Nothing Then Exit Sub
Target.Worksheet.Unprotect Password:="123"
If xRg.Value <> mStr Then xRg.Locked = True
Target.Worksheet.Protect Password:="123"
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Range("A12:O12"), Target) Is Nothing Then
Set mRg = Target.Item(1)
mStr = mRg.Value
End If
End Sub
However, on the worksheet I am looking to apply this to numerous lines (i.e. cells A12:O12, A13:O13, A14:O14, etc). Due to the nature of the worksheet it is required to be locked on a line by line basis. Is it possible to adjust the above code, or alternatively is there a different code that would help achieve this?
Hope this makes sense.
Thanks,
Raj
I am looking for a way to lock lines of cells after data entry. I found the below code which works to lock one line.
Dim mRg As Range
Dim mStr As String
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("A12:O12"), Target) Is Nothing Then
Set mRg = Target.Item(1)
mStr = mRg.Value
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
On Error Resume Next
Set xRg = Intersect(Range("A12:O12"), Target)
If xRg Is Nothing Then Exit Sub
Target.Worksheet.Unprotect Password:="123"
If xRg.Value <> mStr Then xRg.Locked = True
Target.Worksheet.Protect Password:="123"
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Range("A12:O12"), Target) Is Nothing Then
Set mRg = Target.Item(1)
mStr = mRg.Value
End If
End Sub
However, on the worksheet I am looking to apply this to numerous lines (i.e. cells A12:O12, A13:O13, A14:O14, etc). Due to the nature of the worksheet it is required to be locked on a line by line basis. Is it possible to adjust the above code, or alternatively is there a different code that would help achieve this?
Hope this makes sense.
Thanks,
Raj