Sum if there is "something" in a cell?

notsurehowtodothis

New Member
Joined
Aug 16, 2010
Messages
7
I have two columns of information, names in column A and the numbers associated with those names in column B. Some of the cells in column A are blank spaces but have numbers associated, I do not want to sum these numbers, I only want to sum the numbers that have names in column A. I know there is a way to do this, but I just can't figure it out. Thanks!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try:

=SUMPRODUCT(--(A1:A100<>""),B1:B100)
 
Upvote 0
I believe the -- is a double negative. So essentially the code is saying If there is not nothing (i.e. if there is something) in these cells then sum them.

Hope this helps
 
Upvote 0
The -- coerces the conditional statement within the parenthases into a 1 or a 0. By doing this, it creates an array of 1s and 0s. This is useful in SUMPRODUCT because it takes each item in the arrays and multiplies them together, then adds them.

Lets take this data for example:

Excel Workbook
AB
1foo1
2stuff2
3text4
4here5
52
6jack
79
8snacks3
Sheet1
Excel 2003



When we use =SUMPRODUCT(--(A1:A8<>""),B1:B8), the -- makes sumproduct instead look at it in this fashion:

Excel Workbook
AB
111
212
314
415
502
61
709
813
Sheet1
Excel 2003



Then, following the SUMPRODUCT logic, A1*B1+A2*B2+A3*B3+etc... it performs the following:

(1*1)+(1*2)+(1*4)+(1*5)+(0*2)+(1*0)+(0*9)+(1*3) = 15

This can also be done on more than two dimensions, which makes it useful for doing a multi-conditional SUMIF or even used just to simply count over multiple conditions.

Hope that helps! If you would like any further explanation or more examples, lemme know!
 
Upvote 0
The sumproduct isn't really needed here.
Try Sumif

=SUMIF(A1:A100,"<>",B1:B100)
 
Upvote 0
The sumproduct isn't really needed here.
Try Sumif

=SUMIF(A1:A100,"<>",B1:B100)

Hmm... I must have had a typo when I tried doing that... gave me 0 earlier. :biggrin:

This would be the optimal way to do it, as SUMPRODUCT is an array formula and does tend to be sluggish, ESPECIALLY when looking at a lot of data.
 
Upvote 0
Man, you guys are a wealth of information. I appreciate the guidance and I've used the sumproduct now because I only have about 100 rows of data, but sumif goes into my memory bank for future uses.

Thanks again fellas!
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,938
Members
449,197
Latest member
k_bs

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