Thread: time auto entry
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default time auto entry

You don't need any formulas. Leave the col D & C area completely empty.
Discard the previous version. Here is the new version:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set r = Range("B2:B10")
If Intersect(r, t) Is Nothing Then Exit Sub
If t.Offset(0, 1).Value < "" Then Exit Sub
Application.EnableEvents = False
t.Offset(0, 1).Value = Date
t.Offset(0, 2).Value = Time
Application.EnableEvents = True
End Sub

You should adjust the "B2:B10" to suit your needs.
--
Gary''s Student - gsnu200818


"BAKERSMAN" wrote:

Here is my exact scenario. I need the Date to populate in colum C and I need
the time to populate in column D. I have coppied the macro into the
worksheet. Do I need to keep my formula in the cells that I want the static
data to stay in?

"Gary''s Student" wrote:

Say we are entering data in B2 thru B10 and want the date/time recorded in C2
thru C10.

But we want the date/time to be static.

Enter the following event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set r = Range("B2:B10")
If Intersect(r, t) Is Nothing Then Exit Sub
If t.Offset(0, 1).Value < "" Then Exit Sub
Application.EnableEvents = False
t.Offset(0, 1).Value = Now
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200818


"BAKERSMAN" wrote:

I need to have the time and date auto populated in 2 different cells when a
value is enterd into a different cell. Here is the formula i have now

=IF(LEN(B2)=1,NOW(),"")

This formula works perfect but here is the problem I run into. Lets say cell
B2 equals "1", the date will populate in the cell the formula is entered
into. Lets says I enter "1" into cell B3 the next day, the cell with the
formula will populate the current date but the above cell's date will change
to the current date also. Is there a way to keep the date and times from
updating to the current time for all cells with this formula?