Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating days between column of dates and current date 1

Status
Not open for further replies.

Rzrbkpk

Technical User
Mar 24, 2004
84
US
I know this is probably a simple solution, but it is eluding me. I have an Excel worksheet where dates are in column C. In my code, I have inserted a blank column D. I'd like to calculate the difference between each date in column C with the current date (in number of days) and place it on the same row in column D. The only caveat is that there may be some blank cells in column C. Any help is appreciated.
 
A starting point:
Code:
For Each c in Range("C:C")
  If IsDate(c.Value) Then
    c.Offset(0, 1) = Date - c.Value
  End If
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV! That's the basic concept I was looking for. As far as addressing the cells with the blank entries, I tried to complete the conditional statement you started. It works, but instead of stopping at the last row of data, it checks the full range ("C:C"), which makes sense, but not what I'm needing. Column A has an entry in each cell. Could we change the range or offset to compensate for the blank enries in column C?

Code:
Sub Test1()
    
    For Each c In Range("C:C")
        If IsDate(c.Value) Then
        c.Offset(0, 1) = Date - c.Value
        Else
        c.Offset(0, 1) = 0
    End If
    Next
   
End Sub
 
I'd try this:
For Each c In Intersect(Range("C:C"), ActiveSheet.UsedRange)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That took care of it! Thank you!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top