+ Reply to Thread
Results 1 to 5 of 5

Excel 2007 : Sum 4 consecutive cells

  1. #1
    Registered User
    Join Date
    09-14-2011
    Location
    United Sates
    MS-Off Ver
    Excel 2007
    Posts
    3

    Sum 4 consecutive cells

    Hi all,

    I am trying to sum 4 consecutive cells that are above 0.

    Here is an example:


    0,1,2,3,0,4

    The sum I want is the first 4 non-0 numbers, which from that example, would be 6.

    Thank you all in advanced for your help.
    Last edited by NBVC; 09-14-2011 at 02:22 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum 4 consecutive cells

    So if your cells are in say A1:A6, wouldn't that be =SUM(A1:A4)
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    09-14-2011
    Location
    United Sates
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Sum 4 consecutive cells

    Actually, let me clarify

    what I actually want is the sum of the first 4 non-0 numbers.

    another example would be:


    0,0,1,0,0,2,0,4,0,4


    In this example, I want the first non-0, in this case 1, and the next 3 numbers to be summed. The result would be 1+0+0+2 which equates to 3.

    The number does not matter after the first non-0 is added, so long as the first number is greater than 0.

    Hope this is clearer.

    I should also note that the spreadsheet that I am working with contains multiple columns so a simple =sum would not work. Thanks again.

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum 4 consecutive cells

    So if the values are in A1:A10 try either:

    =SUM(OFFSET(INDEX($A$1:$A$10,MATCH(TRUE,INDEX(A1:A10<>0,0),0)),0,0,4,1))

    or

    =SUM(INDEX($A$1:$A$10,MATCH(TRUE,INDEX(A1:A10<>0,0),0)):INDEX($A$1:$A$10,MATCH(TRUE,INDEX(A1:A10<>0,0),0)+3))

    The Offset version is shorter, but is volatile.

  5. #5
    Registered User
    Join Date
    09-14-2011
    Location
    United Sates
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Sum 4 consecutive cells

    Thank you NBVC! Your formula worked perfectly.

+ 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