Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range
Dim LR As Long
Set Rng = Target.Parent.Range("A1,B1")
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Rng) Is Nothing Then Exit Sub
Select Case Target.Address
Case Is = "$A$1"
If Range("D1").Value = "" Then
Target.Offset(0, 3).Value = Target.Value
Else
LR = Range("D" & Rows.Count).End(xlUp).Row
Target.Offset(LR, 3).Value = Target.Value
End If
Case Is = "$B$1"
If Range("E1").Value = "" Then
Target.Offset(0, 3).Value = Target.Value
Else
LR = Range("E" & Rows.Count).End(xlUp).Row
Target.Offset(LR, 3).Value = Target.Value
End If
End Select
End Sub
Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Protect Password:="Password", userinterfaceonly:=True
Next ws
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Unprotect Password:="Password"
'Run code here
Protect Password:="Password"
End Sub
Sub WSunprotect()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Unprotect Password:="Password"
Next ws
End Sub