How to add cell values until a condition changes

G

GBExcel

What formula can I use if I have a row of values where each previous cell to
the left is added until a tested criteria changes?

For example, row A1 to E1 looks like this:

0,1,0,0,1

I need a formula in row A2 to E2 that tests each of the above cells. For
example: B2 will add the values of A1 and B1, because there are only '0's,
(as in 1 '0'), to the left of B1. However, E2 will add the values of C1:E1,
because the values of C1 and D1 are not '1'. A1 and B1 are not included,
because B1 is a '1'.

In other words how can I write a formula that tests if an adjacent cell meets
a criteria? If it does, the formula tests the next cell in the row to see if
it meets the criteria and so on until the formula encounters a cell that does
not meet the criteria is encountered?

For an example, I've upload a simplified spreadsheet to
www.linkm9.com/help2.xlsx
You can refer to this spreadsheet in your reply.

Thanking you.
 
J

Jarek Kujawa

you mean sth. like:

=SUM(INDIRECT(ADDRESS(1,MAX(IF($A$1:D1=1,COLUMN($A$1:D1)))+1)&":"&ADRES
(1,COLUMN(E1))))

?

array-enter this formula (i.e. with CTRL+SHIFT+ENTER instead of just
using ENTER)

HIH
 
J

Jarek Kujawa

there is typo in my formula

here is the correct one:

=SUM(INDIRECT(ADDRESS(1,MAX(IF($A$1:D1=1,COLUMN($A$1:D1)))+1)
&":"&ADDRESS
(1,COLUMN(E1))))

sorry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top