Sum Help

dwgnome

Active Member
Joined
Dec 18, 2005
Messages
441
How can I use a formula to sum values below a certain word in a column. See example below where I need to sum all values just below the word dog:

35</SPAN>
dog</SPAN>
54</SPAN>
34</SPAN>
33</SPAN>
12</SPAN>
dog</SPAN>
20</SPAN>
cat</SPAN>
12</SPAN>
cow</SPAN>
90</SPAN>
23</SPAN>
Total:</SPAN>
74</SPAN>
expected result for dog

<TBODY>
</TBODY>
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Code:
=IF(A1="dog",A2,0)

You can put this in a helper column (column B for example) and then sum based on column B. You could even make this modular by changing the code to:

Code:
=IF(A1=B$1,A2,0)

And then B1 will be "dog" or "cow" and can be changed. Or, if you want a custom UDF to ignore a helper column...

Code:
Function sumWordUnder(crit As Variant, rng As Range) As Long

    For Each cell In rng
        If cell = crit Then sumWordUnder = sumWordUnder + cell.Offset(1, 0)
    Next cell


End Function

The formula would read:
Code:
=sumWordUnder("dog",A2:A19)
 
Upvote 0
Hi!

If your data is in A1:A18, try this formula (Confirm with CSE --> Control + Shift + Enter):

=SUM(IF(A1:A18="dog",A2:A19))

Or this (Without CSE):

=SUMPRODUCT(--(A1:A18="dog"),A2:A19)

Please comment! Blesings!
 
Last edited:
Upvote 0
another way

Excel 2010
ABC
135dog
2dog74
354
434
533
612
7dog
820
9cat
1012
11cow
1290
1323

<tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
C2=SUMIF(A2:A11,C1,A3:A13)

<tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Thank you all, all of your approaches work. The only one I would not use is the helper column version as I don't like to use them when possible. The UDF worked as well, although I do not have the knowledge to make changes to such code, but i guess I can always ask the Board if I ever needed to do so.
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,927
Members
448,533
Latest member
thietbibeboiwasaco

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