Macro and Today's Date

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to insert a macro that when i click a specific set of keys it
insert todays date in the specified cell, how can i do that please

thank you
ant
 
I would like to insert a macro that when i click a specific
set of keys it insert todays date in the specified cell, how
can i do that please

Excel already has this feature...

Ctrl + ; (Control Key plus Semi-Colon Key)

and if you add the Shift Key to that, it inserts the time...

Ctrl + Shift + ; (Control Key plus Shift plus Semi-Colon Key)

Rick
 
You don't really need a macro for that.

Current date Select a cell and press CTRL+;

However, if you want a macro:

Sub insDate()
ActiveCell = Format(Now, "d/m/yyyy")
End Sub
 
Or, even more simply:

Public Sub insDate()
ActiveCell.Value = Date
End Sub

Using Format() to convert Now (which contains both date and time) to a
string, then having XL's parser interpret the string isn't necessary.
How the date is interpreted will depend on your system date settings
(e.g., Format(Date, "d/m/yyyy") on 7 August 2007 (resulting in
7/8/2007), will be interpreted as 8 July 2007 if your date settings are
set to standard US.

The displayed date format will depend on the cell's display format, not
the format you input it with.

If you want a particular format, you should change the cell's
..NumberFormat property, e.g.:

Public Sub insDate()
With ActiveCell
.Value = Date
.NumberFormat = "d/m/yyyy"
End With
End Sub
 
thank you so much, but what if i want it to insert the date in a specified
cell i.e. D10 what shall i do
 
thank you so much, but what if i want it to insert the date in a specified
cell i.e. D10 what shall i do

Using JE McGimpsey's suggested subroutine framework...

Public Sub insDate()
Range("D10").Value = Date
End Sub

Rick
 

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

Back
Top