Solved

Sum variable range in excel

Posted on 2013-01-21
4
436 Views
Last Modified: 2013-01-22
Dear Excel Experts,

Suppose column A contains numbers and zeroes in random order.
I want to create a formula in Column B where in case the value of the Column A for the specific row is non zero, it will produce the sum of that cell in Column A plus the three non zero cells of column A above that row.

For example

Column A contains the values, the non zero being e.g. A6, A9, A10, A14

Column B will sum for example in cell B14 (which is adjacent to the non-zero value at A column), A14 plus the three non zero cells above A14, ie A6+A9+A10

Your reply is much appreciated!!!
0
Comment
Question by:mamelas
  • 2
4 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
Try this formula for row 6

=IF(A6>0,A6+INDEX(A:A,LARGE(IF($A$1:A5>0,ROW($A$1:A5)),1))+INDEX(A:A,LARGE(IF($A$1:A5>0,ROW($A$1:A5)),2))+INDEX(A:A,LARGE(IF($A$1:A5>0,ROW($A$1:A5)),3)),"")
0
 
LVL 50

Expert Comment

by:barry houdini
Comment Utility
Assuming that you have Excel 2007 or later you can use this formula in B6

=IF(A6=0,"",IFERROR(SUM(INDEX(A$6:A6,LARGE(IF(A$6:A6<>0,ROW(A$6:A6)-ROW(A$6)+1),4)):A6),""))

confirm with CTRL+SHIFT+ENTER and copy down column

If there aren't 3 non-zero numbers above you just get blanks, see attached example where A1 has random zeroes/non-zeroes. Press F9 to re-generate random numbers

regards, barry
sumlast4.xlsx
0
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
Comment Utility
...or alittle shorter.....

=IF(A6=0,"",IFERROR(SUM(IF(ROW(A$6:A6)>=LARGE(IF(A$6:A6<>0,ROW(A$6:A6)),4),A$6:A6)),""))

.....still confirmed with CTRL+SHIFT+ENTER

If data starts at a differnt row just change all A6 refs as appropriate

regards, barry
0
 

Author Closing Comment

by:mamelas
Comment Utility
That's what I was looking for. Thank you very much for your help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now