Adding today's date if certain conditions apply

  • Thread starter Thread starter Daniel Lapin
  • Start date Start date
D

Daniel Lapin

I am trying to add the current date when a particular cell is used for data.
The date needs to populate in another cell, and remain unchanged as long as
the other cell has data. How do I do it? I have tried an if-then statement
using today(), but I obviously didn't write it correctly.

Thanks!
 
Daniel,
the easy solution:
=IF(A1<>"",TODAY(),"")

But this will leave the cell with a changing value, whenever you
recalculate.
The other solution is based on an event procedure. Here I am assuming
A1 is the key cell and B1 is the one to be populated with the date at
the moment of the change:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
If Range("A1") <> "" Then
Range("B1") = Date
Else
Range("B1") = ""
End If
End If

To install:
Right click on the sheet tab. Choose View Code... Paste the above
code.

HTH
Kostis Vezerides
 

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