Automatically entering date or time in a cell upon entering

  • Thread starter Thread starter Jim w
  • Start date Start date
J

Jim w

How do I get Excel to automatically enter the date or the
time in a cell when I either enter or leave the cell?
 
Or perhaps you want a constant for your date time stamp, and
want it to change when you enter data in another cell on the
same row and not to change thereafter. Example of an Event macro:
Place current date constant in Column A when Column B changes (#autodate)
http://www.mvps.org/dmcritchie/excel/event.htm#autodate

Instead of = Date in the event macro use =Now
if you want both date and time, and format separately according to what
you want if you don't get the correct format automatically.

At the top of the page read about event macros and how to install them.

The following will enter Date and time into Column A if something is
entered anywhere in the row, unless there is already something in Column A.
http://www.mvps.org/dmcritchie/excel/event.htm#datetimestamp

Private Sub Worksheet_Change(ByVal Target As Range)
If target.row = 1 then exit sub 'don't touch if 1st row
If target.column = 1 then exit sub 'don't touch if Target is col A
If IsEmpty(target) then exit sub 'allow deletion of cell content in entire row
If Not IsEmpty(Cells(Target.Row, 1)) Then Exit Sub 'ignore if already has a value
Cells(Target.Row, 1) = Now
End Sub

To install: Right click on worksheet tab, View code, plop code in
after "Option Explicit"
 
Back
Top