Sub Worksheet_Change(ByVal Target As Range)
Dim CompId
CompId = Environ$("UserName")
Dim PasswordSec
PasswordSec = "MyPassword"
'Locks/Unlocks Column C to L If B does not match the Computer User ID
If Len(Target) = 5 Then
Dim M As Long
M = Target.Row
If Intersect(Target, Range("B:B")) Is Nothing Then Exit Sub
If Target.Text <> CompId Then
ActiveSheet.Unprotect Password:=PasswordSec
Range("C" & M & ":L" & M).Locked = True
ActiveSheet.Protect Password:=PasswordSec
ElseIf Target.Text = CompId Then
ActiveSheet.Unprotect Password:=PasswordSec
Range("C" & M & ":L" & M).Locked = False
ActiveSheet.Protect Password:=PasswordSec
End If
End If
'Locks/Unlocks Column B to L If Column Z matches Completed/Edit
If Target = "Completed" Or Target = "Edit" Then
Dim N As Long
N = Target.Row
If Intersect(Target, Range("Z:Z")) Is Nothing Then Exit Sub
If Target.Text = "Completed" Then
ActiveSheet.Unprotect Password:=PasswordSec
Range("B" & N & ":L" & N).Locked = True
ActiveSheet.Protect Password:=PasswordSec
ElseIf Target.Text = "Edit" Then
ActiveSheet.Unprotect Password:=PasswordSec
Range("B" & N & ":L" & N).Locked = False
ActiveSheet.Protect Password:=PasswordSec
End If
End If
'Adds/Removes Computer User ID from column AB based on entry of Column B
For X = 2 To 901
If Not Intersect(Target, Range("B" & X)) Is Nothing Then
CompId = Environ$("UserName")
If (Len(Range("A" & X)) > 0) Then
Range("AB" & X).Value = CompId
Exit Sub
End If
End If
If Not Intersect(Target, Range("B" & X)) Is Nothing Then
CompId = Environ$("UserName")
If (Len(Range("A" & X)) = 0) Then
Range("AB" & X).Value = " "
Exit Sub
End If
End If
Next X
CompId = Null
End Sub