A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Just a note: In your code is missing an error handling. Therefore, the runtime error 1004 leaves the entire Excel Application without events. I highly recommend to insert an On-Error statement at the beginning of the event handler. At this point you can also turn off sheet protection and disable the events. Like this:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim R As Range, OurValue As String
On Error GoTo error_and_exit
Application.EnableEvents = False
ActiveSheet.Unprotect 'optional password
If Not Intersect(Target, Columns(4), UsedRange) Is Nothing Then
'code for Column D
Set Target = Intersect(Target, Columns(4), UsedRange)
OurValue = "done"
For Each R In Target
If R = OurValue Then
R.EntireRow.Copy Sheets(2).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
R.EntireRow.Delete shift:=xlUp
End If
Next
ElseIf Not Intersect(Target, Columns(1), UsedRange) Is Nothing Then
'code for Column A
Set Target = Intersect(Target, Columns(1), UsedRange)
For Each R In Target
If Not IsEmpty(R) And IsEmpty(R.Offset(0, 1)) Then
R.Offset(0, 1) = Date
End If
Next
ElseIf Not Intersect(Target, [E:E]) Is Nothing Then
'code for Column E
Set Target = Intersect(Target, [E:E])
If Target.Cells.Count > 1 Then Exit Sub
If Not Target.Locked Then Target.Locked = True
End If
error_and_exit:
ActiveSheet.Protect 'optional password
Application.EnableEvents = True
End Sub
Peter