Insert static time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to insert the exact time (hh:mm:ss) I entered data into another cell.
For example when I enter data in cell C:2 I need the exact time it was
entered displayed in cell C:1.
 
You might need a small macro to do this instantly. If you have a cell with
the function =NOW() it will give you the time and date as of the time a
recalculation is done. As soon as you make your cell entry you could hit the
F9 recalc button, this will make the cell with =NOW() show the exact time it
is just after you made your entry. This cell will of course change the next
time you do another recalc so you would have to format a cell as time and
then copy...paste special...values to copy the time value so that it will not
change upon recalculation.
 
I don't think that will work for me. A better example is that I need the
exact time (hh:mm:ss) the data was entered in C:1 to be displayed in B:1 and
then the exact time data was entered in C;2 displayed in B:2 etc.
 
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "C1:C10" '<--- Change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Offset(0, -1).Value = Format(Time, "hh:mm:ss")
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Very basic code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C1:C2")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, -1) = Now()
Application.EnableEvents = True
End Sub

.... in the worksheet class module for the sheet where you are entering data.

Regards

Trevor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top