How to save current date/time in Excel

mmartinez13

New Member
Joined
Sep 1, 2011
Messages
21
Is there a way I can save/record the current date and time in a cell? The current formula I have now is:

=IF(OR(A3=0,G3&H3="PASS"),"",NOW())

The problem I am having is all the previous dates/times will be saved to the current cell. I would like to keep the previous data.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You need to look at the worksheet events and calculate and use a copy and paste cell value to another location like a log sheet.

Right click the worksheet name and then select View Code, then change the General tab at the top to Worksheet and then the procedure drop down to Calculate, then you can add the required code, something like this but not tested

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Calculate()<br><br><SPAN style="color:#00007F">If</SPAN> Range("G3").Value = Now() <SPAN style="color:#00007F">Then</SPAN><br>Range("G3").Copy Destination:=Sheets("Log").Range("A" & Rows.Count).End(xlUp).Offset(1)<br>End <SPAN style="color:#00007F">If</SPAN><br><br><br>End <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
This will save date and time to a worksheet cell (starting cell A1 in this case). Every time you again call this function, it will save the new date and time in the next lower cell.
Code:
Function SaveTimeToNextRowLower()
    Static LocRowAdd
    Dim StartLoc
        StartLoc = "A1"
 
        [COLOR=seagreen]'print date and time[/COLOR]
    Range(StartLoc).Offset(LocRowAdd, 0).Value = "=now()"
        [COLOR=seagreen]'replace now() with its value to stop clock[/COLOR]
    Range(StartLoc).Offset(LocRowAdd, 0).Value = Range(StartLoc).Offset(LocRowAdd, 0).Value
    LocRowAdd = LocRowAdd + 1 [COLOR=seagreen]'row lower next time in function[/COLOR]
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,671
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top