Worksheet cell date advice

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,279
Office Version
  1. 2007
Platform
  1. Windows
Hi.
In cell L13 i used to have =TODAY() but just noticed that somehow its no longer present.
Because of this the last 8 invoice have the dat 14/02/2023

I am looking to apply the date to the L13 cell using VBA so this dont happen again.

Would i be correct to write the code like this,pleae advise.

Rich (BB code):
Range("L13").NumberFormat = "mm/dd/yyyy"

On the worksheet in question i dont know which sub to put it in.

Please advise the above two questions.

Thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
put this in the worksheet code for the sheet where you want it ( right click on the tab and select view code )
VBA Code:
Private Sub Worksheet_Activate()
Range("L13") = Now()
Range("L13").NumberFormat = "mm/dd/yyyy"

End Sub
 
Upvote 0
Solution
There is also a keyboard shortcut that you can input date quickly: CTRL+: (Control - Semicolon).
 
Upvote 0
The TODAY() function ALWAYS returns the current date. So every day you open any workbook that uses it, it will show the current date.
If you want to capture the date in VBA, you can assign it like this:
VBA Code:
Range("L13").Value = Date

EDIT: Regarding the first reply above, just be aware that Date and Now are do NOT the return the same values in VBA.
Now will always return a time component too, and Date will not.
Even if you format a value set using the Now function to use a date format of "m/dd/yyyy", it will still retain the time piece.
That could be important if you are using that date field in calculations. If you are checking to see if two dates are equal, they may appear to be, but Excel may say there are not because of different time components.
 
Upvote 0
put this in the worksheet code for the sheet where you want it ( right click on the tab and select view code )
VBA Code:
Private Sub Worksheet_Activate()
Range("L13") = Now()
Range("L13").NumberFormat = "mm/dd/yyyy"

End Sub


Thanks very much
 
Upvote 0

Forum statistics

Threads
1,216,212
Messages
6,129,546
Members
449,515
Latest member
lukaderanged

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top