Date stamp clears if data removed

Joined
Apr 6, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello,

So I'm using this VBA code to date stamp when data is entered into a cell, but is it possible to keep the cell empty if I remove that data?



VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Application.EnableEvents = False
Range("G" & Target.Row & ":G" & (Target.Row + Target.Rows.Count) - 1).Value = Date
End If
Application.EnableEvents = True
End Sub

Thanks in advance!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Application.EnableEvents = False
Range("G" & Target.Row & ":G" & (Target.Row + Target.Rows.Count) - 1).Value = Date
End If
If Range("A" & Target.Row).Value = "" Then Range("G" & Target.Row) = ""
Application.EnableEvents = True
End Sub
 
Upvote 0
Try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Application.EnableEvents = False
Range("G" & Target.Row & ":G" & (Target.Row + Target.Rows.Count) - 1).Value = Date
End If
If Range("A" & Target.Row).Value = "" Then Range("G" & Target.Row) = ""
Application.EnableEvents = True
End Sub
Thank you for the response!

I just tried this and it will work if I delete the value in A one-by-one, but if I mass select, it will only clear the contents in that first row and not the others :(
 
Upvote 0
Try this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
    
    Set rng = Intersect(Target, Range("A:A"))
    
    If rng Is Nothing Then Exit Sub
    
    Application.EnableEvents = False
    
    For Each cell In rng
        If cell <> "" Then cell.Offset(0, 6).Value = Date
    Next cell

    Application.EnableEvents = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,389
Messages
6,119,232
Members
448,879
Latest member
VanGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top