Link to home
Start Free TrialLog in
Avatar of Jerome Hayes
Jerome HayesFlag for United States of America

asked on

Today function loop

Hello Experts

I'm looking for VBA code to do the following:

loop through cells in column "B" starting at "B2;  put a "Today" function in Column M that calculate the dates in column J starting at "J2".  The formula that i'm currently using and auto filling down in column M is =Today()-J2

Thank you
Avatar of SiddharthRout
SiddharthRout
Flag of India image

Try this

Sub Sample()
    Dim Lastrow As Long
   
    Lastrow = Sheets("Sheet1").Range("B" & Rows.Count).en(xlUp).Row
   
    Range("M2").Formula = "=Today()-J2"
   
    Range("M2").AutoFill Destination:=Range("M2:M" & Lastrow), Type:=xlFillDefault
End Sub

Sid
ASKER CERTIFIED SOLUTION
Avatar of SiddharthRout
SiddharthRout
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jerome Hayes

ASKER

I'm getting an error message in the loop.
Worked great, thanks
You are welcome :)

Sid
Are you still facing any problems?

Sid
Avatar of Dirk Haest
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.