+ Reply to Thread
Results 1 to 3 of 3

Trying to calculate age in number of days

  1. #1
    Registered User
    Join Date
    09-03-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    12

    Trying to calculate age in number of days

    Hello all -

    I'm trying to calculate the age of something by days old. Column N has various dates and i'm trying to bump those dates against a standard End of Month reporting date. For example, in September the date was 9/30/2014. For this month it would be 10/31/2014. Here's the code I have so far but I'm not able to get it to work correctly. All it's doing is playing my EOM date in the adjacent column but i can't figure out what I'm doing wrong. Here's my code:

    Sub AgeCat()
    Dim rptdt1 As Date
    Dim rng As Range
    Dim i As Long

    rptdt1 = DateValue("30/Sep/2014")
    Set rng = Range("N2:N" & Range("N" & Rows.Count).End(xlUp).Row)
    For Each Cell In rng
    If Cell.Value <> "" Then
    Cell.Offset(0, -1).Formula = (rptdt1 - N2)
    End If
    Next
    End Sub

    Thank you for your help. I'm hoping what I'm trying to do is possible, but i'm having trouble creating a function within the macro that uses my Dim rptdt1 with cell data in column N.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Trying to calculate age in number of days

    Why not just use a formula

    =EOMONTH(A2,0)-A2+1

  3. #3
    Registered User
    Join Date
    09-03-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    12

    Re: Trying to calculate age in number of days

    Bob, thanks for your reply I appreciate it. Currently, that's what I'm doing (using a formula). I was looking at a Macro because there are multiple procedures that need to occur to get the spreadsheet workable (adding in data in various fields, etc) and with the thousands of rows I'm working with I figured it would be simpler to throw it in a macro.

    The formula I'm using is =sum($M$1-N2) where M is the EOM date and N is my column of various dates. This gives me the number of days old a particular line is. Example, EOM sep 30 2014, line is august 15, 2014. Formula returns 380 as a number. Having this in a macro would be more ideal as after this calculation occurs I need to convert that number into an age 'bucket' depending on how old it is. For example, anything between 366-730 would simply be 730, anything 61-90 days old would be 90.
    Last edited by V-Clan; 10-14-2014 at 03:24 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Calculate number of days between 2 dates & then assign a number based on the answer
    By MrHappyGoLucky12 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-27-2014, 09:20 PM
  2. [SOLVED] Calculate the number days between two user input days.
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2013, 10:44 PM
  3. [SOLVED] Calculate number of days between two days
    By hecgroups in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-03-2012, 11:28 AM
  4. How to calculate number of days?
    By Maria Reed in forum Excel General
    Replies: 2
    Last Post: 07-28-2011, 04:31 PM
  5. Excel 2007 : cannot get number of days to calculate
    By oldlady in forum Excel General
    Replies: 3
    Last Post: 01-28-2011, 03:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1