Current Date for Data Range.

Shak1701

New Member
Joined
Nov 15, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I'm trying to code today's date in VBA to cover the range of data - so 02/11/2023 in all the cells or 11/02/2023 for those in the US. From this I then need to calculate age from a different set of dates.

My current code is is increasing the date. This is my current code:

VBA Code:
Sub addFormulae()
    lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
    
    Range("S2") = Date
    Range("S2").AutoFill Range("S2:S" & lr)
    
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi, you can populate all the cells at once, rather than first one and filling down, for example..

VBA Code:
Sub addFormulae()
Dim lr As Long
    lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
    
    Range("S2:S" & lr).Value = Date
    
End Sub
 
Upvote 1
Hi, you can populate all the cells at once, rather than first one and filling down, for example..

VBA Code:
Sub addFormulae()
Dim lr As Long
    lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
   
    Range("S2:S" & lr).Value = Date
   
End Sub
Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,069
Members
449,092
Latest member
ipruravindra

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