HLOOKUP to return entire sum of column

Julesdude

Board Regular
Joined
Jan 24, 2010
Messages
197
Hi there. I need help trying to create a simple(ish) forumula. One cell needs to have a formula that uses the HLOOKUP function for range V3:AK3. But what I want it to return is not the value of a particular cell but the sum of the entire column that is identified in this HLOOKUP range.

I also need to trap any errors so if a value is 0 or is an error, to just display a blank.

Can anyone please help?
 
An alternative approach could be to use SUMPRODUCT something like:

=SUMPRODUCT((A5:C5=A1)*(A6:C30000))

(A5:C5=A1) being your criteria and range
(A6:C30000) being the sum range

Results are the same, just to me looks neater and easier to understand.

You can use just row references but my laptop gets a bit funky if I calc on entire rows in 2007.

On returning blank when the returned value =0 it would be more efficient and quicker to calculate if you did this via the cells number format rather than repeating the formula. This is on the presumption you just don't want to see the zero rather than doing some additional calcs(ISBLANK formula or something).
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi Tony, that looks a lot neater. However, in the range A6:C30000 would that total everything in that range or just the target individual column?
 
Upvote 0
It will return just the column that meets the criteria.

Basically if the criteria is met then it returns a 1 if not then 0 and if we multiply it by the corresponding cell value it will end up only summing those which meet the criteria.

So if A5 = A1 then the formula looks like =SUMPRODUCT(1*(A6*C30000)) then as Column 'A' meets the criteria it will check all the cells from A6 to A30000 individually. So if A6 = 20 then it becomes =SUMPRODUCT(1*20) and it does this for all the cells in the range.

It then gives you the ability to go 3D and sum based on another criteria in rows. So say you had years which varied in column Z you could modify the formula to be =SUMPRODUCT((A5:C5=A1)*(Z6:Z30000=2010)*(A6:C30000))
Now you get a sum that meets you original plus those that have 2010 against the row.

Apologies for the long response and if has confused things further.
 
Upvote 0
Thanks Tony. I've adapted to my specific range and it works surprisingly well. It seems a bit slower to work out the formula than before, but can't be sure as my work computer is about 7 years old anyway!

I guess the best way to iron out a '0' return is to put:

=IF(SUMPRODUCT(($J$3:$DY$3=B44)*($J$4:$DY$30000)) > 0, SUMPRODUCT(($J$3:$DY$3=B44)*($J$4:$DY$30000)), "")

...but still, it means calculating twice, but I can't see a way around that.
 
Upvote 0
As I mentioned earlier if all you want to do is not display the zero then the best way would be to use cell formatting.

When formatting the number you probably choose one of standard Number/Accounting/Currency/Date/Percent etc...

The best way to stop zero's displaying is to use a custom format - all you need to know is the structure and some of the basic codes.

So you have four different cell results which Excel can format differently and the convention in the input box is Positive Value ; Negative Value ; Zero Value ; Text and you would separate them with semicolons ";".

So very basically to get rid of the zero you could put in 0;0;; As the third (zero) part is blank it wont display any zero values.

There are many articles on the net (like: http://www.ozgrid.com/Excel/CustomFormats.htm) or even the F1 isn't too bad on this (for a change) for various options.

SUMPRODUCT does come with a health warning that it can be quite calc intensive so use sparingly and I certainly wouldn't recommend copy into 100's of cells.
 
Upvote 0
Thanks Tony, it turned out that because I have to have the SUMPRODUCT formula nearly 100 times, it dramatically slows things down. In the end I opted for the following formula:

=IF(ISERROR(SUM(INDEX($3:$65536,,MATCH(B44,$3:$3,0))) > 0), "", IF(SUM(INDEX($3:$65536,,MATCH(B44,$3:$3,0))) > 0,SUM(INDEX($3:$65536,,MATCH(B44,$3:$3,0))),""))

which takes out both the error and any 0s. I know it's not great as the calculation is done 3 times in the same formula, but even then it's still much faster. I like the SUMPRODUCT though and will probably look at using it again at some point.

I'll also look into CF. I knew it would be easy to just format out the 0s, which I'd normally do. It's just a personal thing really that I find it only hides the 0s from view rather than gets rid of them. Also with CF I find it more hidden if formating is going on in the cell whereas a formula is I guess more visible and on the surface. As I say it's just a personal thing really.
 
Upvote 0
My pleasure.

SUMPRODUCT is good for creating summary reports without need for pivot tables but not so good for doing mass calcs. You could create a UDF to do the same but much faster, but that depends on your VBA abilities.

In Excel 2007 + you get the very useful IFERROR function which would cut the formula down and speed it up.

On CF I have noticed over many years people replacing zero's with various characters and then wondered why calculations off it don't then work. But if it works for you...
 
Upvote 0
Try this,

This will give you 0 if if the answer is error.

=LOOKUP(1E+100,CHOOSE({1,2},0,SUM(INDEX($3:$65536,,MATCH(B44,$3:$3,0)))))

Then use CF or cell format as 0;0;; to hide the zeros.
 
Upvote 0
Hello,

Does your solution only work for sum? I'm trying to do something similar but for "small" and "large" and "average." Thank you.

JT

Apologies, error in my previous sample. Please refer to this one:
Excel Workbook
ABCDE
1Lookup Valabc
2Result5180
3
4aababcabcdabcde
5499360240407843
6423955435956312
7257254364456932
863564102372747
9630592801484127
102074343596972
11649333989536700
12780393542138617
13447610275142248
1415596451339734
15626938151602360
16588581787646501
Sheet1
Excel 2010
Cell Formulas
RangeFormula
B2=IF(COUNTIF($A$4:$E$4,$B$1),SUM(INDEX($A:$E,0,MATCH($B$1,$A$4:$E$4,0))),"")
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top