+ Reply to Thread
Results 1 to 5 of 5

Calculate days between subtotaled list

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Calculate days between subtotaled list

    Good day, Gurus.

    Not sure if this is best accomplished via VBA or Formula, but I know all the smartest people hang out in the Programming forum, so here goes.

    In the attached workbook, I have subtotaled a list of parts. I want to add a formula beside the subtotals, under Column C, "Days BO", that subtracts earliest date in column R from the latest date in column R, for each part number.

    I have added a simple formula to the attached example that does what I want, but the full sheet will be thousands of lines weekly, with varying part numbers, and different counts. I don't know how to take the count function into account so I can copy a single formula all the way down the sheet.

    Thanks in advance for any help you can offer.
    Attached Files Attached Files
    Last edited by hutch@edge.net; 04-17-2009 at 03:59 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Calculate days between subtotaled list

    Where on your sheet are you talking about? I don't see any date functions other than the dates themselves in column R.

    Can you provide several answers for some of the rows on your example sheet and highlight them so we can see what your goal is?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Calculate days between subtotaled list

    You are correct, JB. The dates I want to calculate are located in column R. I want to count how many days passed between the first date the part was backordered and the last date,

    I have attached a new zip file, showing several examples in green. On any parts with only one entry, the formula should always return a 1. If there are multiple entries, it should count the number of days between the earliest and the latest entry.

    Thanks.
    Attached Files Attached Files

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Calculate days between subtotaled list

    Ah, I see it now in column C. This should take care of it, run this macro to update your column C values:
    Option Explicit
    
    Sub AddDaysBO()
    Dim lastrow As Long, firstrow As Long, i As Integer
    Application.ScreenUpdating = False
    lastrow = Range("A" & Rows.Count).End(xlUp).Row - 1   'takes Grand Total off end
    firstrow = 2
    
    For i = 2 To lastrow
        If Range("A" & i).Value Like "*Total" Then
            Range("C" & i).FormulaR1C1 = "=R" & i - 1 & "C18-R" & firstrow & "C18"
            Range("C" & i).NumberFormat = "General"
            firstrow = i + 1
        End If
    Next i
    
    Application.ScreenUpdating = True
    End Sub
    Last edited by JBeaucaire; 04-17-2009 at 03:44 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Calculate days between subtotaled list

    Works beautifully, JB.

    Thanks!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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