PDA

View Full Version : Solved: VLOOKUP as a sum



icthus123
07-05-2007, 02:44 AM
Hi,

Is there an excel formula which will let me find the sum of rows in a column of a table which meet a certain criteria. I suspect that some variation on VLOOKUP could do this but as far as I know VLOOKUP can only be made to return one value from a table not a sum of values.

Any ideas?

unmarkedhelicopter
07-05-2007, 03:00 AM
you are looking at multiple options here from standard sumif to array formulae with sumproduct in the middle.
What is your problem ?

icthus123
07-05-2007, 03:22 AM
you are looking at multiple options here from standard sumif to array formulae with sumproduct in the middle.
What is your problem ?

The problem is I'm not sure how to do it! :dunno

icthus123
07-05-2007, 03:36 AM
I've tried to use this

=SUMPRODUCT((OFFSET(Sheet1!$C$4,0,0,COUNTA(Sheet1!$C:$C),1)=Sheet3!C9)*(OFF SET(Sheet1!$J$4,0,0,COUNTA(Sheet1!$J:$J),1)))


But it doesn't work! I want to find the sum in column J where column C = the value in sheet3!C9. Any ideas?

unmarkedhelicopter
07-05-2007, 04:18 AM
=sumproduct((Sheet1!C1:C1000=Sheet3!C9)*Sheet1!J1:J1000)

icthus123
07-05-2007, 04:26 AM
that comes up with a #VALUE error too! Any ideas why?

Bob Phillips
07-05-2007, 04:27 AM
It is probably because you have a different number of rows in column C and J, so when you build the dynamic arrays, they are different sizes, and SUMPRODUCT chokes on that.

Try using the same sizing range

=SUMPRODUCT((OFFSET(Sheet1!$C$4,0,0,COUNTA(Sheet1!$C:$C),1)=Sheet3!C9)*(OFF SET(Sheet1!$J$4,0,0,COUNTA(Sheet1!$C:$C),1)))

icthus123
07-05-2007, 04:34 AM
It is probably because you have a different number of rows in column C and J, so when you build the dynamic arrays, they are different sizes, and SUMPRODUCT chokes on that.

Try using the same sizing range

=SUMPRODUCT((OFFSET(Sheet1!$C$4,0,0,COUNTA(Sheet1!$C:$C),1)=Sheet3!C9)*(OFF SET(Sheet1!$J$4,0,0,COUNTA(Sheet1!$C:$C),1)))

I'm still getting a #VALUE error. :banghead:

Bob Phillips
07-05-2007, 04:50 AM
Then you must have problems in the data.

icthus123
07-05-2007, 05:01 AM
Well, at the moment column C has this data
212
212
213



And column J has this data got from a formula

?54.00
?54.00
?87.60

Any ideas what might be wrong?

unmarkedhelicopter
07-05-2007, 05:20 AM
Post the book

icthus123
07-05-2007, 05:33 AM
I can't cause it's too big, even when I compress it! And when I just copy the relevant bits into another file it works! Do you think it could be the formulae in column J that it doesn't like?

Bob Phillips
07-05-2007, 05:41 AM
Works fine for me even with formulae.

What is in C1:C3 and J1:J3?

icthus123
07-05-2007, 05:49 AM
Works fine for me even with formulae.

What is in C1:C3 and J1:J3?

C1:C3 just has the text 212, 212, 213

And J1:J3 have the formula

=IF(NOT(ISBLANK(H4)),I4*G4, " ")

icthus123
07-05-2007, 05:50 AM
Sorry misunderstood you waht I have you was C4:C6, etc.

There's nothing in the first two rows. And just column heads in row three.

Bob Phillips
07-05-2007, 05:59 AM
Change that formula to

=IF(NOT(ISBLANK(H4)),I4*G4,0)

icthus123
07-05-2007, 06:03 AM
Thanks a lot, that works fine now! Except it's defeated the reason I put " " instead of 0, that's that I want those rows to be hidden until there's a value in H4. Is there a way I can still have it hidden? Now it has a zero in it (or in my case ? - ).

icthus123
07-05-2007, 06:05 AM
Actually I've sorted it! I've used conditional formatting to make the text invisible when there's nothing in H4.

Bob Phillips
07-05-2007, 06:15 AM
Change the cell format to

_-?* #,##0.00_-;-?* #,##0.00_-;""

icthus123
07-05-2007, 06:39 AM
Thanks a lot! Works perfectly!