You may be working on databases or tables in Excel that contain changing data which needs to be timestamped. You could manually enter the date or time every time you work (or use the keyboard shortcut Ctrl + : which brings in the current date and time). However, if you want to automate this task, you could use the following macro.
This code works within the target worksheet and gets activated when a change is detected in any cells in Column C (the 3rd column). It responds to the change by entering the current date and time in the column next to Column C – the 4th column.
Private Sub Worksheet_Change(ByVal Target As Range)If Target.Column = 3 ThenApplication.EnableEvents = FalseCells(Target.Row,4).Value = Date + TimeApplication.EnableEvents = TrueEnd IfEnd Sub
Adjust the column numbers as appropriate for you. If you wanted just the date and not the time, remove “+ Time” at the end of the third line of the code.
Remember to place the code within the focus worksheet (Sheet1) coding area, and not in ThisWorkbook or a Module.