I'm trying to write a macro in vba that will automatically add the date when I enter data in a certain column.
I got that part working.
Then i found, that if i deleted the entry, the date stayed.
So, I tried modifying the code to empty the date cell if I deleted the entry.... but now it doesnt work at all.
Could anyone tell me what I've done wrong here/how to fix it?
Here is what I tried:
I got that part working.
Then i found, that if i deleted the entry, the date stayed.
So, I tried modifying the code to empty the date cell if I deleted the entry.... but now it doesnt work at all.
Could anyone tell me what I've done wrong here/how to fix it?
Here is what I tried:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim dd As Range, ee As Range
Set dd = Intersect(Target, Range("d:d"))
Set ee = Intersect(Target, Range("e:e"))
On Error GoTo ERRHANDLER
If (dd) Is Nothing Then
Target.Offset(0, -3) = ""
Else
If Not (dd) Is Nothing Then
Target.Offset(0, -3) = Date
End If
End If
If (ee) Is Nothing Then
Target.Offset(0, -3) = ""
Else
If Not (ee) Is Nothing Then
Target.Offset(0, 1) = Date
End If
End If
Exit Sub
ERRHANDLER:
Exit Sub
End Sub