+ Reply to Thread
Results 1 to 3 of 3

Count of rows in range sum until target is met, preferably working from the bottom up

  1. #1
    Registered User
    Join Date
    01-25-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    17

    Count of rows in range sum until target is met, preferably working from the bottom up

    I'm trying to sum a range of cells to reach a certain target. Once that target is met, I need to know the number of rows it took to reach that target value and retrieve the value from an adjacent cell.
    In this example I need to sum up rows of apples&bananas to get a total fruit count. Once that fruit count reaches a target (40) I need to know the #rows it took to get there and what the associated color is from the adjacent cell.

    Ideally I would start at a particular bottom cell and work my way up until the sum reached the target. This seems to really complicate things but it's how my data source is structured.
    If it's way too complicated to do it bottom-up, then I can work with a developer to get the dataset flip-flopped so that I can work with it top-down.

    I've seen a few example formulas that are close but they always deal with summing up a single column and I've been unable to adjust it properly to make it a range-based sum. I'm also not 100% sure how to convert these into something that would produce the associated color.

    excel.range.sum.until.target2.jpg

    Here are the examples I've found while searching that get me part-of-the-way to where I need to be (*Note these only work top-down):
    =SUM(OFFSET(A2,0,0,MAX(INDEX((SUBTOTAL(9,OFFSET(A2,0,0,ROW(1:99999),1))<F1)*ROW(1:99999),,))+1,1))
    =MAX(INDEX((SUBTOTAL(9,OFFSET(A2,0,0,ROW(1:99999),1))<F1)*ROW(1:99999),,))+1
    Attached Images Attached Images

  2. #2
    Forum Contributor
    Join Date
    05-18-2021
    Location
    London, Ontario
    MS-Off Ver
    365
    Posts
    115

    Re: Count of rows in range sum until target is met, preferably working from the bottom up

    If I were doing this I'd just split it into a few different columns.
    Column D would be the horizontal sum (e.g. =SUM(A2:B2) or however many columns across there are).
    Then column E the running total. So starting from the bottom, say the last row is 14 then E14 = D14, E13 = D13 + E14, E12 = D12 + E13, etc.

    Then in a cell somewhere else you can lookup the first row in Column E that is greater than the target. Could use something like =LARGE(IF(E$2:E$14>=40,ROW(E$2:E$14),""),1), which returns the largest row whose value is greater to or equal to 40.

    Then to find the total rows that it spans you just take the difference of that value from the bottom row.

    Not the perfect solution but hope it helps

    edit: to find the associated colour just do index(A:A, {value that you got for the row}, 1)

  3. #3
    Registered User
    Join Date
    01-25-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Count of rows in range sum until target is met, preferably working from the bottom up

    Hi - thank you for the reply. This would work except the "last row" that needs to be the starting point for the sum is variable. So I can't create a fixed column with the upwards-heading SUM because I'll re-use this formula in a bunch of places and one time it might be row E14, another time it might be E8, etc.

+ 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. [SOLVED] Count the number of cell rows address from top to bottom?
    By rayhen in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-16-2020, 02:10 AM
  2. [SOLVED] Target.Adress not working when pasting a range over a column that is tracked for changes
    By Beginer25 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-20-2019, 11:06 AM
  3. [SOLVED] Return Row no. for Lookup from bottom of range, ignoring bottom n no. of rows
    By naira in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 12-27-2018, 12:07 AM
  4. Lookup from bottom of range, ignoring bottom n no. of rows
    By naira in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 12-05-2018, 04:26 AM
  5. [SOLVED] Hide rows IF #N/A (preferably without marco)
    By The excel apprentice in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-04-2016, 09:40 AM
  6. Private Sub Worksheet_Change(ByVal Target As Range) not working
    By kaseyleigh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-05-2013, 07:12 AM
  7. putting count of the number of rows at the bottom
    By lpdarspe in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-21-2006, 07:55 AM

Tags for this Thread

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