+ Reply to Thread
Results 1 to 14 of 14

Help with summing prior four non zero values please?

  1. #1
    Registered User
    Join Date
    06-04-2013
    Location
    Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    16

    Help with summing prior four non zero values please?

    Hello, can anyone help please?
    I have a column full of data, generally numbers from 1 to 10, but with a lot of zero's.
    Sometimes their could be more than 20 consecutive zeros. Can someone give me a formula for summing the previous four non zero values? The four non zero values could be in four cells, but it could be several before 4 non zero values occur.

    I have attached an example- I hope that explains better what I can't work out

    Thank you, Christopher
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    11-12-2007
    Posts
    38

    Re: Help with summing prior four non zero values please?

    Type =if(A1=0,"",A1) in to cell C1 and drag formula in C1 down. Next, type =SUM(C1:C19) in to cell C20.

  3. #3
    Registered User
    Join Date
    11-12-2007
    Posts
    38

    Re: Help with summing prior four non zero values please?

    Hang on, don't think I read your Q properly, gimme a few minutes

  4. #4
    Registered User
    Join Date
    06-04-2013
    Location
    Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Help with summing prior four non zero values please?

    Tricky one, isn't it?

  5. #5
    Registered User
    Join Date
    06-04-2013
    Location
    Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Help with summing prior four non zero values please?

    Quote Originally Posted by ChristopherHac View Post
    Tricky one, isn't it?
    Has this stumped everyone- or have I explained wrongly?

  6. #6
    Registered User
    Join Date
    06-04-2013
    Location
    Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Help with summing prior four non zero values please?

    Quote Originally Posted by ChristopherHac View Post
    Has this stumped everyone- or have I explained wrongly?
    Can anyone even give a pointer?

  7. #7
    Registered User
    Join Date
    06-04-2013
    Location
    Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Help with summing prior four non zero values please?

    Just trying to jump up the list a bit

  8. #8
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Re: Help with summing prior four non zero values please?

    If you can work with a VBA solution, here is one:

    Create a new module in VBA and paste this in:

    Please Login or Register  to view this content.
    Now use the formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    instead of A10, just use the row where you are now for example, so when you drag down, A10 will change to whatever row you're on, but $A$1 will stay the same.

    Hope this works for you.
    Duncan

  9. #9
    Registered User
    Join Date
    06-04-2013
    Location
    Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Help with summing prior four non zero values please?

    Thank you so much- got it all sorted- Christopher

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with summing prior four non zero values please?

    Formula?

    =SUMIF(INDEX(Rng, ROWS(Rng)):INDEX(Rng, LARGE(ROW(Rng) * (Rng <> 0), 4) - ROW(Rng) + 1), "<>0")

    Replace Rng with the range of interest, and the formula MUST be confirmed with Ctrl+Shift+Enter
    Entia non sunt multiplicanda sine necessitate

  11. #11
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Help with summing prior four non zero values please?

    Standing on the shoulders of giants; with shg's formula, in B4 of your example

    =IF(COUNT(IF($A$1:A4<>0, $A$1:A4,""))>=4, SUMIF(INDEX($A$1:A4, ROWS($A$1:A4)):INDEX($A$1:A4, LARGE(ROW($A$1:A4) * ($A$1:A4 <> 0), 4) - ROW($A$1:A4) + 1), "<>0"), 0) entered with CNTRL SHFT ENTER

    copied down gives you exactly the same results as your example.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  12. #12
    Registered User
    Join Date
    11-12-2007
    Posts
    38

    Re: Help with summing prior four non zero values please?

    Wow, I love this site, humble people with big intellects helping out those less knowledgeable !!!

  13. #13
    Registered User
    Join Date
    06-04-2013
    Location
    Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Help with summing prior four non zero values please?

    Quote Originally Posted by ChemistB View Post
    Standing on the shoulders of giants; with shg's formula, in B4 of your example

    =IF(COUNT(IF($A$1:A4<>0, $A$1:A4,""))>=4, SUMIF(INDEX($A$1:A4, ROWS($A$1:A4)):INDEX($A$1:A4, LARGE(ROW($A$1:A4) * ($A$1:A4 <> 0), 4) - ROW($A$1:A4) + 1), "<>0"), 0) entered with CNTRL SHFT ENTER

    copied down gives you exactly the same results as your example.

    Thank you, works well

  14. #14
    Registered User
    Join Date
    06-04-2013
    Location
    Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Help with summing prior four non zero values please?

    Agreed- if the world could be run by excel experts!!

+ 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