ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating non-volatile Date (https://www.excelbanter.com/excel-programming/323428-creating-non-volatile-date.html)

Nigel[_7_]

Creating non-volatile Date
 
Hi All
I have a requirement to, from within VBA, store the
current date into a worksheet.cell. But for that date to
be non-volatile.

If I use the system date functions then this will always
change, after the worksheet is reloaded. What is the best
approach to overcome this?

Cheers
Nigel

Harald Staff

Creating non-volatile Date
 
Hi Nigel

Sub DateMe()
Sheets(1).Range("C14").Value = Date
End Sub

HTH. best wishes Harald

"Nigel" skrev i melding
...
Hi All
I have a requirement to, from within VBA, store the
current date into a worksheet.cell. But for that date to
be non-volatile.

If I use the system date functions then this will always
change, after the worksheet is reloaded. What is the best
approach to overcome this?

Cheers
Nigel




WindsurferLA

Creating non-volatile Date
 
Nigel wrote:
Hi All
I have a requirement to, from within VBA, store the
current date into a worksheet.cell. But for that date to
be non-volatile.

If I use the system date functions then this will always
change, after the worksheet is reloaded. What is the best
approach to overcome this?

Cheers
Nigel


I suspect what you want to do is write a macro to
(1) copy the cell containing the date
and
(2) paste the contents of the cell back into the cell using PASTE
SPECIAL / VALUE

You can obtain the appropriate code by merely recording a macro of the
operation being performed.

Ed

Creating non-volatile Date
 
If this is going to be used in a Workbook_Open event macro or called
automatically from another procedure, wrap it in an IF. That way, if it's
already been done once, it won't change unexpectedly.
' Assuming A1 has the non-volatile date,
If Range("A1") < "" Then
' code to capture date
End If

Ed

"windsurferLA" wrote in message
...
Nigel wrote:
Hi All
I have a requirement to, from within VBA, store the
current date into a worksheet.cell. But for that date to
be non-volatile.

If I use the system date functions then this will always
change, after the worksheet is reloaded. What is the best
approach to overcome this?

Cheers
Nigel


I suspect what you want to do is write a macro to
(1) copy the cell containing the date
and
(2) paste the contents of the cell back into the cell using PASTE
SPECIAL / VALUE

You can obtain the appropriate code by merely recording a macro of the
operation being performed.




[email protected]

Creating non-volatile Date
 

Nigel wrote:
Hi All
I have a requirement to, from within VBA, store the
current date into a worksheet.cell. But for that date to
be non-volatile.

If I use the system date functions then this will always
change, after the worksheet is reloaded. What is the best
approach to overcome this?

Cheers
Nigel


Hi -

This puts the both the data and the time in cell A1:

ThisWorkbook.Sheets("NameOfSheet").Cells(A1).Value = Now()

where you replace "NameOfSheet" with the worksheet name that you
actually are using. Also adjust the Cells(A1) to the proper cell
reference that you need.

By using the attribute ".Value" of the function "Now()" in ".Cells(A1)"
of the worksheet "ThisWorkbook.Sheets("NameOfSheet")" you get the
nonvolatile results of the function "Now()". It's a great way of
timestamping any and all workbooks and worksheets...

Hope this helps

John



All times are GMT +1. The time now is 10:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com