View Single Post
  #18  
Old May 4th, 2010, 04:57 PM posted to microsoft.public.excel.worksheet.functions
Gord Dibben
external usenet poster
 
Posts: 20,252
Default Can Excel automatically insert current date in a cell?

Copy/paste this code to your sheet module.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo stoppit
Application.EnableEvents = False
If Target.Address = "$A$1" Then
Target.Offset(0, 1).Value = Format(Now, "mm-dd-yyyy hh:mm")
End If
stoppit:
Application.EnableEvents = True
End Sub

If you want this for any cell in Column A use this code instead.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'when entering data in a cell in Col A
On Error GoTo stoppit
Application.EnableEvents = False
If Target.Cells.Column = 1 Then
n = Target.Row
If Me.Range("A" & n).Value "" Then
Me.Range("B" & n).Value = Format(Now, "mm-dd-yyyy hh:mm")
End If
End If
stoppitl:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Mon, 3 May 2010 23:30:02 -0700, Felix
wrote:

I would like to put something in cell A1 and the current date will be shown
in cell b1 but static. How to use the following code to achieve this? Thanks.

"Paul B" wrote:

AdrianXing, you could put =TODAY() in a cell and it will up date, if you
don't want the date to change after you put it in use some code in the
workbook open event to do it, like this

Sheets("Sheet1").Range("A1") = Date

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"AdrianXing" wrote in message
...
Does anyone know of a function that can make Excel automatically insert
the
current date into a cell when a file is opened up?