ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro for data and time (https://www.excelbanter.com/excel-discussion-misc-queries/242514-macro-data-time.html)

rexmann

Macro for data and time
 
Hi

I have recently started to use Excel 2007 and have tried to create a macro
that records the date and time. I have recorded the key strokes ctrl ; and
space and ctrl shift ;

Unfortunately it just enters the date at the time I recorded the macro. I
would like to record just the key strokes so it puts in the date and time at
the time the macro is run. Is this possible? I am not a great expert at
visual basic but can normally fudge a solution! Any suggestion to do this?

Any help greatly appreciated

rexmann

Jan Karel Pieterse

Macro for data and time
 
Hi Rexmann,

Unfortunately it just enters the date at the time I recorded the macro. I
would like to record just the key strokes so it puts in the date and time at
the time the macro is run. Is this possible? I am not a great expert at
visual basic but can normally fudge a solution! Any suggestion to do this?


For the time, make sure the code within your macro is like this:

ActiveCell.Value = Time

and for the date:

ActiveCell.Value = Date

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com


MS-Exl-Learner

Macro for data and time
 
Try this.

Past the below code in Excel VBA Module and assign shortcut key for that.

Press ALT+F11 and go to Insert and click Module. And paste the below code.

Sub DateandTime()
ActiveCell = Now()
End Sub

After pasting the code close the VBA and press ALT+F8, the DateandTime Macro
will appear. Just select it and select Options and give your desired
keyboard button as shortcut key to run the macro.

If you want to show the cells including seconds just select the cells and
Goto Format and select custom and paste this format [$-409]m/d/yy h:mm:ss
AM/PM;@

If this post helps, Click Yes!

--------------------
(MS-Exl-Learner)
--------------------

"rexmann" wrote:

Hi

I have recently started to use Excel 2007 and have tried to create a macro
that records the date and time. I have recorded the key strokes ctrl ; and
space and ctrl shift ;

Unfortunately it just enters the date at the time I recorded the macro. I
would like to record just the key strokes so it puts in the date and time at
the time the macro is run. Is this possible? I am not a great expert at
visual basic but can normally fudge a solution! Any suggestion to do this?

Any help greatly appreciated

rexmann


rexmann

Macro for data and time
 
Hi

Brilliant, worked a treat, thank you (plus the seconds bit is an added bonus)

Cheers Rexmann

"Ms-Exl-Learner" wrote:

Try this.

Past the below code in Excel VBA Module and assign shortcut key for that.

Press ALT+F11 and go to Insert and click Module. And paste the below code.

Sub DateandTime()
ActiveCell = Now()
End Sub

After pasting the code close the VBA and press ALT+F8, the DateandTime Macro
will appear. Just select it and select Options and give your desired
keyboard button as shortcut key to run the macro.

If you want to show the cells including seconds just select the cells and
Goto Format and select custom and paste this format [$-409]m/d/yy h:mm:ss
AM/PM;@

If this post helps, Click Yes!

--------------------
(MS-Exl-Learner)
--------------------

"rexmann" wrote:

Hi

I have recently started to use Excel 2007 and have tried to create a macro
that records the date and time. I have recorded the key strokes ctrl ; and
space and ctrl shift ;

Unfortunately it just enters the date at the time I recorded the macro. I
would like to record just the key strokes so it puts in the date and time at
the time the macro is run. Is this possible? I am not a great expert at
visual basic but can normally fudge a solution! Any suggestion to do this?

Any help greatly appreciated

rexmann



All times are GMT +1. The time now is 07:18 PM.

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