I am running the code below to lock cells following data entry. I need to do this for multiple columns while skipping columns. My attempts to add columns to the range results in errors.

Steven Taylor 1 Reputation point
2022-01-27T13:25:50.84+00:00

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
On Error Resume Next
Set xRg = Intersect(Range("A1:A10001"), Target)
If xRg Is Nothing Then Exit Sub
Target.Worksheet.Unprotect Password:="JamesBond"
If xRg.Value <> mStr Then xRg.Locked = True
Target.Worksheet.Protect Password:="JamesBond"
End Sub

0 comments No comments
{count} votes