Inputting Dates Formula?

S

Scott

Is there anyway to input a date in a cell when data first appears in another
cell? For instance, if I entered data in cell A1, is there a way that B1
will record that date, but not change it the next day?

Thanks!
 
G

Gary''s Student

You could use an event macro. Say we want to record in column B the data
when entry is made in column A. Insert the following event macro in the
worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range
Set A = Range("A:A")
If Intersect(A, Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, 1).Value = Date
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
 
S

Scott

Gary,
Yes, this does work. However, how do I change the destination cell for the
date to appear on? For instance, what do I do if I want it to display in
Column W? How do I edit your code?
 
G

Gary''s Student

First thanks for trying a macro solution. (many folks have "macrophobia").
To use W instead of B change:
Target.Offset(0, 1).Value = Date
into:
Target.Offset(0, 22).Value = Date

You see 1 is for B
2 is for C


etc.
 
S

Scott

Ok, I figured that out. Actually I figured out how to change that shortly
after I posted my reply.

But one more question. What if I wanted to substitute something as the
match results? For instance, what happens if I want to display the date in
B1 when A1 equals "Complete." Also, if/when A1 changes and does not match or
text is deleted, I would want to clear the date in B1.
 

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

Top