"Excel - Get Date"

F

Fraggs

Is there a way to have a cell so that when it is clicked on or somethin
it automaticaly enters the date. Probs get it off the computer cloc
or something
 
B

Bob Phillips

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("A1")) Is Nothing Then
With Target
.Value = Format(Date, "dd mmm yyyy")
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

This is worksheet code, so to enter it, right-click on the sheet tab, select
View Code from the menu, and paste the code.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
P

Patrick Molloy

search this NG for time stamp
One way is to use the sheets selection change event (
right click the sheet tab to get to its code page)
The following will place a time stamp if cell C2 is
selected...

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)
Dim sText As String
If Target.Address = "$C$2" Then
sText = Format$(Date, "dd-mmm-yy")
sText = sText & " " & Format$(Now, "HH:MM")
Target.Value = sText
End If
End Sub

Patrick Molloy
Microsft Excel MVP
 
A

AA2e72E

If you want the current data in a cell, simply type =TODAY() in it. BUT: As this is a formula, the data will automatically change whenever the workbook is recalculated
If you want the data inserted only when the user enters that particular cell

Use this code: it must be in the Sheet

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range
If Not Application.Intersect(Target, Range("A5")) Is Nothing The
Range("A5") = Dat
End I
End Su

NOTE: just usiing Date ensures that the current date is shown in the date format found in Regional Settings on your PC.
 
T

TH

You will need to go to the Sheet object and choose the event
SheetSelectionChange

In that event (macro) insert this code:

If target.address = range("A1").address then range("A1") = date

Where A1 is the cell, if clicked on, you want the current date/time.
Format that cell to display date, time or both.

TH
 
Top