How preserve the value of NOW() or TODAY()?

N

Nathan Gutman

I like to write code to preserve the value of NOW() or TODAY().
When user opens the workbook the first time current system date + 30
day should be recorded and it should not change with subsequent
openings of the workbook.
I can do that manually inserting TODAY() into A1 then copy/paste
special/values only to B1. Then make C1 = B1 + 30
How to do it in an efficinet macro.
I know that I can use Range("A1").Copy Range("B1") but this copies the
formula not just the value.
 
T

Tom Ogilvy

With Range("B1")
.Formula = Range("A1").Value + 30
.Numberformat = "mm/dd/yyyy"
End With
 
T

Tom Ogilvy

or just

With Range("B1")
.Value = Date + 30
.Numberformat = "mm/dd/yyyy"
End With
 
N

Nathan Gutman

Thanks Tom, both seem to be working.
Where and how did you learn how to do thigns like that?
 
N

Nathan Gutman

Thanks Tom, both seem to be working.
Where and how did you learn how to do things like that?
 
N

Nathan Gutman

Hi Tom,
In the second example how does the code know that Date is the value of
Today() from A1?
 
T

Tom Ogilvy

It doesn't. Date is the VBA equipvalent of the worksheet function =today().
I was suggesting that there was no reason to store a date in A1 if the only
purpose was to use it as a reference for advancing 30 days.
 
Top