I added some code to erase the corresponding D cell when G is manually erased. By itself it works fine. However on the same worksheet I also have code that enters todays date in the D cell when data is edited in G, which is interfering with the other code. Is there a way I can make the date entry in D cell only happen when data is first added to G, not when deleted from G, or if G is edited? So that way when G gets erased so will the date in D.

This is my code currently:

Option Explicit
 
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub

        If Not Intersect(Target, Range("G1:G5000")) Is Nothing Then

            With Target(1, -2)

                .Value = Date

            End With

        End If

On Error Resume Next
If Intersect(Target, Range("G6:G1048576")) Is Nothing _
Or Target.Cells.Count > 1 _
Or Target.Value = vbNullString Then Exit Sub

If Target.Offset(0, -1).Value = vbNullString Then
Beep
MsgBox ("Bar code not found, please enter item manually.")
ActiveCell.Offset(-1, -1).Value = InputBox("New item name.", "Item Name.")

End If

    If Target.Cells.Count > 1 Then Exit Sub
     
    If Not Intersect(Target, Range("G2:G" & Cells(Rows.Count, "D").End(xlUp).Row)) Is Nothing Then
        If Target.Value = vbNullString Then
            Range("D" & Target.Row) = vbNullString
        End If
    End If

End Sub
Thank you for your time.