![]() |
Macro and Today's Date
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 |
Macro and Today's Date
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 |
Macro and Today's Date
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 "Antonius" wrote: 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 |
Macro and Today's Date
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 In article , JLGWhiz wrote: 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 |
Macro and Today's Date
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 "JE McGimpsey" wrote: 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 In article , JLGWhiz wrote: 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 |
Macro and Today's Date
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 |
All times are GMT +1. The time now is 07:33 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com