Forum Discussion
DeenaJ
Jul 17, 2024Copper Contributor
Automatically populate date to cell in Excel (with VBA)
I've create a VBA in Excel but would like to respective entries when data is added to automatically populate a date and time stamp in Column 3 of the worksheet. I was able to use a formula that worke...
HansVogelaar
Jul 18, 2024MVP
Thank you, but that is a cell formula, not VBA code.
DeenaJ
Jul 19, 2024Copper Contributor
I was able to create the action in Sheet1 of the VBA project. Here is the code I used:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
On Error Resume Next
If Target.Value = "" Then
Target.Offset(0, 2) = ""
Else
Target.Offset(0, 2).Value = Format(Now, "mm/dd/yyyy HH:mm:ss")
End If
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
On Error Resume Next
If Target.Value = "" Then
Target.Offset(0, 2) = ""
Else
Target.Offset(0, 2).Value = Format(Now, "mm/dd/yyyy HH:mm:ss")
End If
End If
End Sub