0

In My sheet when I update Cells in D column the Cell in C column will show date of update , now I need if I delete the info in D cell to Delete the info in C cell not as formula as VBA code Code below :

 `Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Column <> 4 Then Exit Sub
  If Target.Cells.Count > 1 Then Exit Sub
   With Target.Offset(0, -1)
    .Value = Now
     .NumberFormat = " MM/DD/YY hh:mm Am/PM"
  End With

   Dim RangeA As Range
   Set RangeA = Range("D10:D10000")
    If Application.CountBlank(RangeA) = RangeA.Cells.Count Then
    Range("C10:C10000").ClearContents
     End If
     End Sub`
0

1 Answer 1

4

I would recommend adding an if-statement to support your activities, such that:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column <> 4 Then Exit Sub
    If Target.Cells.Count > 1 Then Exit Sub
    If Target.Value <> "" then
        With Target.Offset(0, -1) 
            .Value = Now
            .NumberFormat = " MM/DD/YY hh:mm Am/PM"
        End With
    Else
        Target.Offset(,-1).ClearContents
    End If
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

@Aboudezoua wonderful; please mark as your answer (the check mark left of my post) if this has resolved your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.