# Thread: Sum based on Value (Excel 2003)

1. ## Sum based on Value (Excel 2003)

Hi all

I can use =SUMIF(A1:A6,"=2") to sum all 2 in a range.
Can SUM(IF....) do the same ? I can't get the formula to work

cheers

2. ## Re: Sum based on Value (Excel 2003)

It's not clear what you want. Jerry has posted one possible solution. Depending on what you want to accomplish, you might use the following array formula (confirm with Ctrl+Shift+Enter) instead:

=SUM(IF(A1:A6=2,A1:A6))

3. ## Re: Sum based on Value (Excel 2003)

You could use:

=COUNTIF(A1:A6,2)*2

4. ## Re: Sum based on Value (Excel 2003)

SUMIF needs three arguements.
Perhaps =SUMIF(A1:A6, 2, A1:A6) will work for you.

(The =COUNTIF(A1:A6,2)*2 is possibly faster)

5. ## Re: Sum based on Value (Excel 2003)

If the range to test the condition on and the range to sum are equal, you can omit the third argument of SUMIF - see SUMIF.

6. ## Re: Sum based on Value (Excel 2003)

Thanks to all.

How does the =COUNTIF(A1:A6,2)*2 works?

cheers

7. ## Re: Sum based on Value (Excel 2003)

The original formula

=SUMIF(A1:A6,"=2")

adds the cells in the range A1:A6 whose value equals 2. If there is 1 such cell, the sum is 2, if there are 2 such cells, their sum is 2*2 = 4, if there are 3 such cells, their sum is 3*2 = 6 etc.
In other words, the sum is 2 times the number of cells that equal 2. COUNTIF calculates that number.

If you had wanted to sum the cells whose value equals 37, the sum would be 37 times the number of cells that equal 37, or

=COUNTIF(A1:A6,37)*37

8. ## Re: Sum based on Value (Excel 2003)

Hi Hans

Great explaination! Thanks

cheers

9. ## Re: Sum based on Value (Excel 2003)

1] COUNTIF can use in this way :

=SUM(COUNTIF(A1:A6,2)*{1,1})

2] Or, using SUMIF, and SUMPRODUCT function

=SUMIF(A1:A6,2)

=SUMPRODUCT((A1:A6=2)*A1:A6)

Please take a look of this :

SUMIF can accept the whole Column A, but SUMPRODUCT cannot.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•