+ Reply to Thread
Results 1 to 7 of 7

Sum of Last Five Cells that have a value

  1. #1
    Registered User
    Join Date
    07-25-2016
    Location
    Illinois, USA
    MS-Off Ver
    2012
    Posts
    6

    Cool Sum of Last Five Cells that have a value

    So I have a sheet that contains the type and number of fish caught on specific dates

    column A contains every day
    column B contains the number of bass caught that day (if any, could blank)
    column C contains the number of blue gill caught that day (if any, could be blank)

    I would like column D to be the number of bass caught in the previous 5 days where bass were caught

    So i basically need a formula that sums of the last five cells that have a value in them.
    Ideally if there were not 5 cells that had values in it (like at the beginning of a month) I would like it to read n/a but that really isnt a big deal

    If anyone could help me I would greatly appreciate it.

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum of Last Five Cells that have a value

    Try this...

    Data Range
    B
    C
    D
    1
    ------
    ------
    ------
    2
    68
    268
    3
    80
    4
    30
    5
    8
    6
    71
    7
    69
    8
    9
    20
    10
    84
    11
    12
    62
    13
    14
    15
    33
    16


    This array formula** entered in D2:

    =IFERROR(SUM(B20:INDEX(B2:B20,LARGE(IF(B2:B20<>"",ROW(B2:B20)-ROW(B2)+1),5))),"N/A")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    07-25-2016
    Location
    Illinois, USA
    MS-Off Ver
    2012
    Posts
    6

    Re: Sum of Last Five Cells that have a value

    THanks for the reply. I for some reason am getting an error. I attached the file to this. Could you please take a look at it and tell me what I have done wrong?

    Also this is just an example. My actual spreadsheet will contain over 2,500 rows. Do I need to update the formula to reflect this?
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    07-25-2016
    Location
    Illinois, USA
    MS-Off Ver
    2012
    Posts
    6

    Re: Sum of Last Five Cells that have a value

    Quote Originally Posted by Tony Valko View Post
    Try this...

    This array formula** entered in D2:

    =IFERROR(SUM(B20:INDEX(B2:B20,LARGE(IF(B2:B20<>"",ROW(B2:B20)-ROW(B2)+1),5))),"N/A")
    Update: I was able to fix it and i am no longer receiving errors but for some reason that values that are being returned make no sense. I attached my updated example file. I also slightly miss spoke. I would like column D to be the number of bass caught in the previous 5 trips not including the "current' one. If you look at my attached example to this post I included a column of what the formula should return
    Attached Files Attached Files

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum of Last Five Cells that have a value

    Ok, I see the problem.

    You want the sum for each row.

    My formula was summing the last (bottom most) 5 numbers in the entire range.

    This works but it requires there be a cell above the first formula cell (for example, a column header).

    This array formula** entered in D2 and copied down:

    =IF(COUNT(B$2:B2)<=5,"N/A",SUM(LOOKUP(LARGE(ISNUMBER(B$1:B1)*ROW(B$1:B1),{1,2,3,4,5}),ROW(B$1:B1),B$1:B1)))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Last edited by Tony Valko; 07-25-2016 at 07:55 PM.

  6. #6
    Registered User
    Join Date
    07-25-2016
    Location
    Illinois, USA
    MS-Off Ver
    2012
    Posts
    6

    Re: Sum of Last Five Cells that have a value

    Yep that worked! thank you very much.

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum of Last Five Cells that have a value

    You're welcome. Thanks for the feedback!

+ 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. Replies: 4
    Last Post: 02-11-2015, 09:02 AM
  2. Replies: 0
    Last Post: 01-21-2015, 12:05 PM
  3. [SOLVED] Linking cells globally to allow users the ability to change cells on separate sheet/cells.
    By V1gilante in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-18-2014, 10:47 PM
  4. combining many cells in one cells keeping character font and hyperlinks of all cells
    By mankind00 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2012, 09:41 AM
  5. Replies: 4
    Last Post: 06-17-2011, 08:53 AM
  6. Formula: Drop Down List -> Choose Option Finds Cells & Replace Cells with Cells
    By g00glethis1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-14-2010, 01:10 PM
  7. Replies: 2
    Last Post: 06-24-2010, 04:53 PM

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