Macro for data and time

R

rexmann

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
 
J

Jan Karel Pieterse

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
 
M

Ms-Exl-Learner

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!
 
R

rexmann

Hi

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

Cheers Rexmann

Ms-Exl-Learner said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top