NOW keeps updating previous entries

thb63

New Member
Joined
Jan 10, 2010
Messages
2
I've set up a macro to enter the NOW function to have the date and time. I want this so it shows down to the seconds. The steps are here:

Go to an empty cell<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Click Tools, Macro, Record New Macro . . .<o:p></o:p>
Give a proper name such as Insert_Date<o:p></o:p>
Hold Shift and type a “D” into the Shortcut Key box<o:p></o:p>
Select Store In Personal Macro Workbook (unless they always use the same workbook then you can save it to that file, then whomever uses the file can use the macro)<o:p></o:p>
Click OK<o:p></o:p>
Type “=now()”<o:p></o:p>
Click the green checkmark next to the formula bar<o:p></o:p>
Copy and paste special values<o:p></o:p>
Click the Stop button on the macro toolbar

The problem is it keeps changing the previous entries to the last date/time entered using the macro. Any suggestions? Using CTRL SHIFT : doesn't give me down to the seconds like I need.

Thanks,
Tom
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I've set up a macro to enter the NOW function to have the date and time. I want this so it shows down to the seconds. The steps are here:

Go to an empty cell<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Click Tools, Macro, Record New Macro . . .<o:p></o:p>
Give a proper name such as Insert_Date<o:p></o:p>
Hold Shift and type a “D” into the Shortcut Key box<o:p></o:p>
Select Store In Personal Macro Workbook (unless they always use the same workbook then you can save it to that file, then whomever uses the file can use the macro)<o:p></o:p>
Click OK<o:p></o:p>
Type “=now()”<o:p></o:p>
Click the green checkmark next to the formula bar<o:p></o:p>
Copy and paste special values<o:p></o:p>
Click the Stop button on the macro toolbar

The problem is it keeps changing the previous entries to the last date/time entered using the macro. Any suggestions? Using CTRL SHIFT : doesn't give me down to the seconds like I need.

Thanks,
Tom

Now you have to copy and paste the value into the cell instead of the formula.

I use this, it's attached to a button so I select the cell I want the date in and click the button. (Not formatted for seconds, but you can change that)

Code:
Sub CurrDateTime()
' CurrDateTime
    ActiveCell.FormulaR1C1 = "=NOW()"
    Range(ActiveCell.Address).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
End Sub
 
Upvote 0
Hello

Or just.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> datetime()<br>  ActiveCell = <SPAN style="color:#00007F">Date</SPAN> & " " & Time<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
A minor modification of Rekd's code might be:
Rich (BB code):
Sub CurrDateTime()
' CurrDateTime
With Activecell
  .Formula = "=NOW()"
  .Value = .Value
  .NumberFormat = "DD/MM/YYYY HH:SS"
End With
End Sub
You can then attach this code to a button and adjust the line in red to give the format style that you want. I'd suggest avoiding using the .Select in VBA code as it can slow your macro down, cause the screen to flicker and creates other problems too (search the other entires on this board for a better explanation if you want)
 
Upvote 0
Hello Rekd

Thanks. :biggrin:

But be aware that it returns text to display the seconds, as requested.
If you wanted to return, a proper date, use the below and format as required.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> datetime()<br>  ActiveCell = <SPAN style="color:#00007F">Date</SPAN> + Time<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,215,744
Messages
6,126,621
Members
449,322
Latest member
Ricardo Souza

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