Excel – Can Excel perform a count-if-like sum mixing absolute and relative cell coordinates

microsoft excelmicrosoft-excel-2010worksheet-function

Suppose I have a spreadsheet structured a bit like this

  _A____B____C____D____E____F_____
1 |XFoo|XBar|YFoo|ZBar|XBaz|Result
2 |8   |3   |0   |1   |100 |  (*)
3 |2   |1   |1   |20  |10  |  (*)

I want to count the sum of all cells in each row over columns A through E, only where those column headings (row 1) are prefixed with the letter X.

So, F2 would be calculated as A2+B2+E2=111 because A1, B1, and E1 all start with the letter X. Likewise, F3 would be 13.

How can I express this in an Excel formula, using built-in functions (no custom scripts)?

Best Answer

SUMIF function

You use the SUMIF function to sum the values in a range that meet criteria that you specify.

Syntax: SUMIF(range, criteria, [sum_range])

For your example, use the following:

=SUMIF(A$1:E$1,"X*",A2:E2)
Related Question