Hi there,
One last try - let me know how the following goes (note my comments as well).
Regards,
Robert
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strMyPassword, strColumnChg As String
Dim lngLastRow, lngRowChg As Long
'Set your desired password to this variable.
strMyPassword = "YourPasswordHere"
ActiveSheet.Unprotect Password:=strMyPassword
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
strColumnChg = Left(Target.Address(False, False), 1)
lngRowChg = Val(Mid(Target.Address(False, False), 2, Len(Target.Address(False, False)) - 1))
'Code will only work if the change has occurred in Column E and from rows _
17 to the last row used in Column A (inclusive).
If strColumnChg = "E" And _
lngRowChg >= 17 Or _
lngRowChg <= lngLastRow Then
If Target.Value = "DI" Or _
Target.Value = "LTC" Or _
Target.Value = "Z" Then
With Range("F" & lngRowChg)
If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect Password:=strMyPassword
End If
.Locked = False
If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect Password:=strMyPassword
End If
.ClearContents
If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect Password:=strMyPassword
End If
.Interior.Color = RGB(192, 192, 192)
If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect Password:=strMyPassword
End If
.Locked = True
End With
Else
With Range("F" & lngRowChg)
If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect Password:=strMyPassword
End If
.Locked = False
If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect Password:=strMyPassword
End If
.Interior.ColorIndex = xlNone
End With
End If
End If
ActiveSheet.Protect Password:=strMyPassword
End Sub
Bookmarks