Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 55
Default SUM Range Between Zeros

Greetings Excel Gurus,

I've searched the knowlege base for a formula to solve my issue, but have
found nothing.

Here's an illustration (where "A" is the column and numbers 1-6 downward are
rows):

A
1 <header
2 5
3 0
4 15
5 20
6 <formula

The formula in A6 would sum cells A4 and A5 (all values 0 between the
formula and first cell upward that contains a zero (wouldn't include cell
A2).

Thanks for your help!

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default SUM Range Between Zeros

Try this:

=IF(COUNTIF(A2:A5,0),SUM(INDEX(A2:A5,MATCH(0,A2:A5 ,0)):A5),"")

Biff

"Exceller" wrote in message
...
Greetings Excel Gurus,

I've searched the knowlege base for a formula to solve my issue, but have
found nothing.

Here's an illustration (where "A" is the column and numbers 1-6 downward
are
rows):

A
1 <header
2 5
3 0
4 15
5 20
6 <formula

The formula in A6 would sum cells A4 and A5 (all values 0 between the
formula and first cell upward that contains a zero (wouldn't include cell
A2).

Thanks for your help!



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,118
Default SUM Range Between Zeros

Here you go....

NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX((A2:A5=0)*ROW(A2:A5),0) )):A5)

or...the ARRAY FORMULA version
(committed with ctrl+shift+enter, instead of enter)
A6: =SUM(INDEX(A2:A5,MAX((A2:A5=0)*ROW(A2:A5))):A5)

OR....if there may be blank values.....
NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX(ISNUMBER(A2:A5)*(A2:A5= 0)*ROW(A2:A5),0))):A5)

ARRAY FORMULA
A6: =SUM(INDEX(A2:A5,MAX(ISNUMBER(A2:A5)*(A2:A5=0)*ROW (A2:A5))):A5)

Does that help?
***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Greetings Excel Gurus,

I've searched the knowlege base for a formula to solve my issue, but have
found nothing.

Here's an illustration (where "A" is the column and numbers 1-6 downward are
rows):

A
1 <header
2 5
3 0
4 15
5 20
6 <formula

The formula in A6 would sum cells A4 and A5 (all values 0 between the
formula and first cell upward that contains a zero (wouldn't include cell
A2).

Thanks for your help!

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 55
Default SUM Range Between Zeros

Thank you, Ron. It works, but if I mix the references and extend the formula
down the range, subsequent zeros entered make the references below it return
errors. For example, when I changed the references and dragged it down the
column to extended the range, and then added zeroes within the range
(overwriting the formula) all the formulas below it returned an error

Formula with changed references, dragged down to row 20
=SUM(INDEX($A$2:$A200,MAX(INDEX(($A$2:$A200=0)*ROW ($A$2:$A200),0))):$A200)

So, I need the formula to dynamically sum the values between the zeros
within the entire range (A2: A200); or really, I need it to sum the values
above it 0, until it reaches the first 0 above it.

Sorry if this is confusing! I'll be overwriting the formula in some cells in
range A2:A200 with zeros and need the formula to adjust for this (and count
all values above it 0, until it reaches the next zero, upward.

Thanks!

"Ron Coderre" wrote:

Here you go....

NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX((A2:A5=0)*ROW(A2:A5),0) )):A5)

or...the ARRAY FORMULA version
(committed with ctrl+shift+enter, instead of enter)
A6: =SUM(INDEX(A2:A5,MAX((A2:A5=0)*ROW(A2:A5))):A5)

OR....if there may be blank values.....
NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX(ISNUMBER(A2:A5)*(A2:A5= 0)*ROW(A2:A5),0))):A5)

ARRAY FORMULA
A6: =SUM(INDEX(A2:A5,MAX(ISNUMBER(A2:A5)*(A2:A5=0)*ROW (A2:A5))):A5)

Does that help?
***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Greetings Excel Gurus,

I've searched the knowlege base for a formula to solve my issue, but have
found nothing.

Here's an illustration (where "A" is the column and numbers 1-6 downward are
rows):

A
1 <header
2 5
3 0
4 15
5 20
6 <formula

The formula in A6 would sum cells A4 and A5 (all values 0 between the
formula and first cell upward that contains a zero (wouldn't include cell
A2).

Thanks for your help!

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 733
Default SUM Range Between Zeros

Exceller wrote...
Thank you, Ron. It works, but if I mix the references and extend the formula
down the range, subsequent zeros entered make the references below it return
errors. For example, when I changed the references and dragged it down the
column to extended the range, and then added zeroes within the range
(overwriting the formula) all the formulas below it returned an error

Formula with changed references, dragged down to row 20
=SUM(INDEX($A$2:$A200,
MAX(INDEX(($A$2:$A200=0)*ROW($A$2:$A200),0))):$A2 00)

....

Ron's formula has a bug in it. First off,

MAX(ISNUMBER(A2:A5)*(A2:A5=0)*ROW(A2:A5))

returns 2, 3, 4 or 5, but the row indices for A2:A5 are 1, 2, 3 and 4.
An off-by-one bug. If the last zero is in the last row, the MAX term
returns one more than the number of rows in the range, and that leads
to a #REF! error.

So, I need the formula to dynamically sum the values between the zeros
within the entire range (A2: A200); or really, I need it to sum the values
above it 0, until it reaches the first 0 above it.

....

If the formula should return zero if the value immediately above it
were zero, try

=SUMPRODUCT(--(ROW(rng)LOOKUP(2,1/(rng=0),ROW(rng))),rng)

and if the range could contain blank cells, try

=SUMPRODUCT(--(ROW(rng)LOOKUP(2,1/ISNUMBER(rng)/
(rng=0),ROW(rng))),rng)



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,118
Default SUM Range Between Zeros

If you want the formula to be able to distinguish input values from formulas,
then a User Defined Function may be in your future. Otherwise....maybe this?

A6: =SUM(INDEX($A$2:A5,MAX(INDEX(($A$2:A5=0)*ROW($A$2: A5)-ROW($A$1),0))):A5)

Copy that formula down

Note: the first formula after the inputs will return the correct value, the
remaining formulas will feed upon those above.

Is that something you can work with?

***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Thank you, Ron. It works, but if I mix the references and extend the formula
down the range, subsequent zeros entered make the references below it return
errors. For example, when I changed the references and dragged it down the
column to extended the range, and then added zeroes within the range
(overwriting the formula) all the formulas below it returned an error

Formula with changed references, dragged down to row 20
=SUM(INDEX($A$2:$A200,MAX(INDEX(($A$2:$A200=0)*ROW ($A$2:$A200),0))):$A200)

So, I need the formula to dynamically sum the values between the zeros
within the entire range (A2: A200); or really, I need it to sum the values
above it 0, until it reaches the first 0 above it.

Sorry if this is confusing! I'll be overwriting the formula in some cells in
range A2:A200 with zeros and need the formula to adjust for this (and count
all values above it 0, until it reaches the next zero, upward.

Thanks!

"Ron Coderre" wrote:

Here you go....

NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX((A2:A5=0)*ROW(A2:A5),0) )):A5)

or...the ARRAY FORMULA version
(committed with ctrl+shift+enter, instead of enter)
A6: =SUM(INDEX(A2:A5,MAX((A2:A5=0)*ROW(A2:A5))):A5)

OR....if there may be blank values.....
NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX(ISNUMBER(A2:A5)*(A2:A5= 0)*ROW(A2:A5),0))):A5)

ARRAY FORMULA
A6: =SUM(INDEX(A2:A5,MAX(ISNUMBER(A2:A5)*(A2:A5=0)*ROW (A2:A5))):A5)

Does that help?
***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Greetings Excel Gurus,

I've searched the knowlege base for a formula to solve my issue, but have
found nothing.

Here's an illustration (where "A" is the column and numbers 1-6 downward are
rows):

A
1 <header
2 5
3 0
4 15
5 20
6 <formula

The formula in A6 would sum cells A4 and A5 (all values 0 between the
formula and first cell upward that contains a zero (wouldn't include cell
A2).

Thanks for your help!

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 55
Default SUM Range Between Zeros

Harlan
Ron
Your formulas work wonderfully. Thanks so much for your expertise and
assistance!
T--I couldn't get your formula to work in this scenario, but I've modified
it for another spreadsheet and it works great there--thanks!
Many, many thanks to all.
Regards,
Exceller

"Ron Coderre" wrote:

If you want the formula to be able to distinguish input values from formulas,
then a User Defined Function may be in your future. Otherwise....maybe this?

A6: =SUM(INDEX($A$2:A5,MAX(INDEX(($A$2:A5=0)*ROW($A$2: A5)-ROW($A$1),0))):A5)

Copy that formula down

Note: the first formula after the inputs will return the correct value, the
remaining formulas will feed upon those above.

Is that something you can work with?

***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Thank you, Ron. It works, but if I mix the references and extend the formula
down the range, subsequent zeros entered make the references below it return
errors. For example, when I changed the references and dragged it down the
column to extended the range, and then added zeroes within the range
(overwriting the formula) all the formulas below it returned an error

Formula with changed references, dragged down to row 20
=SUM(INDEX($A$2:$A200,MAX(INDEX(($A$2:$A200=0)*ROW ($A$2:$A200),0))):$A200)

So, I need the formula to dynamically sum the values between the zeros
within the entire range (A2: A200); or really, I need it to sum the values
above it 0, until it reaches the first 0 above it.

Sorry if this is confusing! I'll be overwriting the formula in some cells in
range A2:A200 with zeros and need the formula to adjust for this (and count
all values above it 0, until it reaches the next zero, upward.

Thanks!

"Ron Coderre" wrote:

Here you go....

NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX((A2:A5=0)*ROW(A2:A5),0) )):A5)

or...the ARRAY FORMULA version
(committed with ctrl+shift+enter, instead of enter)
A6: =SUM(INDEX(A2:A5,MAX((A2:A5=0)*ROW(A2:A5))):A5)

OR....if there may be blank values.....
NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX(ISNUMBER(A2:A5)*(A2:A5= 0)*ROW(A2:A5),0))):A5)

ARRAY FORMULA
A6: =SUM(INDEX(A2:A5,MAX(ISNUMBER(A2:A5)*(A2:A5=0)*ROW (A2:A5))):A5)

Does that help?
***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Greetings Excel Gurus,

I've searched the knowlege base for a formula to solve my issue, but have
found nothing.

Here's an illustration (where "A" is the column and numbers 1-6 downward are
rows):

A
1 <header
2 5
3 0
4 15
5 20
6 <formula

The formula in A6 would sum cells A4 and A5 (all values 0 between the
formula and first cell upward that contains a zero (wouldn't include cell
A2).

Thanks for your help!

  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,118
Default SUM Range Between Zeros

Thanks for the feedback, Exceller.


***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Harlan
Ron
Your formulas work wonderfully. Thanks so much for your expertise and
assistance!
T--I couldn't get your formula to work in this scenario, but I've modified
it for another spreadsheet and it works great there--thanks!
Many, many thanks to all.
Regards,
Exceller

"Ron Coderre" wrote:

If you want the formula to be able to distinguish input values from formulas,
then a User Defined Function may be in your future. Otherwise....maybe this?

A6: =SUM(INDEX($A$2:A5,MAX(INDEX(($A$2:A5=0)*ROW($A$2: A5)-ROW($A$1),0))):A5)

Copy that formula down

Note: the first formula after the inputs will return the correct value, the
remaining formulas will feed upon those above.

Is that something you can work with?

***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Thank you, Ron. It works, but if I mix the references and extend the formula
down the range, subsequent zeros entered make the references below it return
errors. For example, when I changed the references and dragged it down the
column to extended the range, and then added zeroes within the range
(overwriting the formula) all the formulas below it returned an error

Formula with changed references, dragged down to row 20
=SUM(INDEX($A$2:$A200,MAX(INDEX(($A$2:$A200=0)*ROW ($A$2:$A200),0))):$A200)

So, I need the formula to dynamically sum the values between the zeros
within the entire range (A2: A200); or really, I need it to sum the values
above it 0, until it reaches the first 0 above it.

Sorry if this is confusing! I'll be overwriting the formula in some cells in
range A2:A200 with zeros and need the formula to adjust for this (and count
all values above it 0, until it reaches the next zero, upward.

Thanks!

"Ron Coderre" wrote:

Here you go....

NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX((A2:A5=0)*ROW(A2:A5),0) )):A5)

or...the ARRAY FORMULA version
(committed with ctrl+shift+enter, instead of enter)
A6: =SUM(INDEX(A2:A5,MAX((A2:A5=0)*ROW(A2:A5))):A5)

OR....if there may be blank values.....
NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX(ISNUMBER(A2:A5)*(A2:A5= 0)*ROW(A2:A5),0))):A5)

ARRAY FORMULA
A6: =SUM(INDEX(A2:A5,MAX(ISNUMBER(A2:A5)*(A2:A5=0)*ROW (A2:A5))):A5)

Does that help?
***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Greetings Excel Gurus,

I've searched the knowlege base for a formula to solve my issue, but have
found nothing.

Here's an illustration (where "A" is the column and numbers 1-6 downward are
rows):

A
1 <header
2 5
3 0
4 15
5 20
6 <formula

The formula in A6 would sum cells A4 and A5 (all values 0 between the
formula and first cell upward that contains a zero (wouldn't include cell
A2).

Thanks for your help!

  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 55
Default SUM Range Between Zeros

You're welcome. This is a great resource and service, and the MS MVP program
and its members deserve a lot of credit and many thanks.
Thanks again.

"Ron Coderre" wrote:

Thanks for the feedback, Exceller.


***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Harlan
Ron
Your formulas work wonderfully. Thanks so much for your expertise and
assistance!
T--I couldn't get your formula to work in this scenario, but I've modified
it for another spreadsheet and it works great there--thanks!
Many, many thanks to all.
Regards,
Exceller

"Ron Coderre" wrote:

If you want the formula to be able to distinguish input values from formulas,
then a User Defined Function may be in your future. Otherwise....maybe this?

A6: =SUM(INDEX($A$2:A5,MAX(INDEX(($A$2:A5=0)*ROW($A$2: A5)-ROW($A$1),0))):A5)

Copy that formula down

Note: the first formula after the inputs will return the correct value, the
remaining formulas will feed upon those above.

Is that something you can work with?

***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Thank you, Ron. It works, but if I mix the references and extend the formula
down the range, subsequent zeros entered make the references below it return
errors. For example, when I changed the references and dragged it down the
column to extended the range, and then added zeroes within the range
(overwriting the formula) all the formulas below it returned an error

Formula with changed references, dragged down to row 20
=SUM(INDEX($A$2:$A200,MAX(INDEX(($A$2:$A200=0)*ROW ($A$2:$A200),0))):$A200)

So, I need the formula to dynamically sum the values between the zeros
within the entire range (A2: A200); or really, I need it to sum the values
above it 0, until it reaches the first 0 above it.

Sorry if this is confusing! I'll be overwriting the formula in some cells in
range A2:A200 with zeros and need the formula to adjust for this (and count
all values above it 0, until it reaches the next zero, upward.

Thanks!

"Ron Coderre" wrote:

Here you go....

NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX((A2:A5=0)*ROW(A2:A5),0) )):A5)

or...the ARRAY FORMULA version
(committed with ctrl+shift+enter, instead of enter)
A6: =SUM(INDEX(A2:A5,MAX((A2:A5=0)*ROW(A2:A5))):A5)

OR....if there may be blank values.....
NON-array formula
A6: =SUM(INDEX(A2:A5,MAX(INDEX(ISNUMBER(A2:A5)*(A2:A5= 0)*ROW(A2:A5),0))):A5)

ARRAY FORMULA
A6: =SUM(INDEX(A2:A5,MAX(ISNUMBER(A2:A5)*(A2:A5=0)*ROW (A2:A5))):A5)

Does that help?
***********
Regards,
Ron

XL2002, WinXP


"Exceller" wrote:

Greetings Excel Gurus,

I've searched the knowlege base for a formula to solve my issue, but have
found nothing.

Here's an illustration (where "A" is the column and numbers 1-6 downward are
rows):

A
1 <header
2 5
3 0
4 15
5 20
6 <formula

The formula in A6 would sum cells A4 and A5 (all values 0 between the
formula and first cell upward that contains a zero (wouldn't include cell
A2).

Thanks for your help!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Wrap Text Across Columns & Rows Michael Excel Dude Excel Discussion (Misc queries) 1 September 4th 06 02:14 AM
Duplicate Range Names by worksheet FlaAl Excel Discussion (Misc queries) 0 May 24th 06 05:14 PM
Help with using range names in sum function soteman2005 Excel Worksheet Functions 2 November 28th 05 04:43 PM
Array to named range conversion... i-Zapp Excel Discussion (Misc queries) 4 October 25th 05 09:09 PM


All times are GMT +1. The time now is 05:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"