Record Date and Time when cell is changed, but remove record when cell is empty

normajean

New Member
Joined
Mar 13, 2014
Messages
14
Hi all,

I'm completely new to VBA but I think I may need to use it. I'm entering data into column "P". I need the corresponding cells in column "I" to display the date and time that data is entered into "P". I found this code that has worked well:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 16 Then
Application.EnableEvents = False
Cells(Target.Row, 9).Value = Date + Time
Application.EnableEvents = True


End If

End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)


End Sub


The only problem with this is that when I remove the data from column "P", the date and time is still there. I want a modified version of this VBA (or a totally different one) that says something like if "P" is empty, then "I" will be empty.

Any help would be really appreciated!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Range("P:P")) Is Nothing Then Exit Sub
    If Target.Value = vbNullString Then
        Target.Offset(, -7).Value = vbNullString
    Else
        Target.Offset(, -7).Value = Now
    End If
End Sub
 
Upvote 0
Hey, thanks for the response. I tried this but it highlighted the word "Intersect" in the third line and said "Compile Error: Argument not optional".
 
Upvote 0

Forum statistics

Threads
1,215,999
Messages
6,128,196
Members
449,432
Latest member
Novice Excel User

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