• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

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
0
allwork32
Asked:
allwork32
  • 4
  • 2
1 Solution
 
SiddharthRoutCommented:
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
0
 
SiddharthRoutCommented:
A slight change. Paste this code in a module.

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

Open in new window


Sid
0
 
allwork32Author Commented:
I'm getting an error message in the loop.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
allwork32Author Commented:
Worked great, thanks
0
 
SiddharthRoutCommented:
You are welcome :)

Sid
0
 
SiddharthRoutCommented:
Are you still facing any problems?

Sid
0
 
DhaestCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now