Hi viola,
If it's always going to be today's date that you enter, then use DBY's suggestion of Ctrl-; which will enter today's date and it will always stay as that date. (If that is the case, please give him the reputation for answering your question(by clicking the star symbol on the left) - don't give it me, that wouldn't be fair!)
If you want today's date automatically, then try this code, which will enter TODAY in the active cell then make it permanent so it doesn't update:
Sub DateStaySame()
ActiveCell.FormulaR1C1 = "=TODAY()"
ActiveCell.Copy
ActiveCell.PasteSpecial xlPasteValues
End Sub
If you want it to go in a specific cell, try this, altering the cell reference as required:
Sub DateStaySameInA1()
Range("A1").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
ActiveCell.Copy
ActiveCell.PasteSpecial xlPasteValues
End Sub
If you want the date the spreadsheet was created (which might not be today), try this:
Sub CreatedDate()
ActiveCell.Value = Format(ActiveWorkbook.BuiltinDocumentProperties("Creation Date"), "dd.mm.yyyy")
End Sub
Just for completeness, if you want the date the spreadsheet was last modified, use this:
Sub ModifiedDate()
ActiveCell.Value = Format(ActiveWorkbook.BuiltinDocumentProperties("Last Save Time"), "dd.mm.yyyy")
End Sub
Either of the two previous can be made to enter in a set cell by adding 'Range("A1").Select' as in the second code above. Also, you can alter the date format to whatever you want; if you want your default short date format, use "short date".
Finally, if you want any of these to run automatically when the workbook runs, open the Visual Basic Editor by pushing Alt-F11. Then click the folder on the left called 'Microsoft Excel Objects', then click the 'ThisWorkbook' module and enter the macro like this:
Private Sub Workbook_Open()
'Macro text goes here
End Sub
I hope that all makes sense and is of some help.
Regards,
Aardigspook
Bookmarks