0

Suppose columns A, B and C contain numbers. I want to sum everything in any of these columns if they are listed in an extra column or cell. The columns to be summed can be anywhere in the spreadsheet. And this must be a function rather than a VBA script.

For instance, column D could contain cells containing "A" and "C", or perhaps a single cell containing "A, C". My function (E2) would therefore output the sum of the values in columns A and C.

A   B   C   D   E
1   4   7   A   30
2   5   8   C
3   6   9

For bonus complication, I want the sum to be a SUMIF, in order to filter out the rows in columns A, B and C, based on a matching criteria. So, in the example below, I categorise the rows in columns A, B and C with a colour (F). E now displays two sums - the totals from columns A and C with category red (E2) and the sum with category green (E3). I fully expect the formulas in E2 and E3 to be different, in order to specify the different matching criteria.

A   B   C   D   E   F
1   4   7   A   18  red
2   5   8   C   12  red
3   6   9           green

Thanks.

5
  • 2
    Your question is somewhat confusing. Please clarify it and include what you have attempted on your own so far. Also share any functions you may have tried.
    – CharlieRB
    Jan 2, 2014 at 13:39
  • This is quite confusing. Is column F used to categorise by colour, or is it to specify which colours are your filter criteria? Or both?
    – Andi Mohr
    Jan 2, 2014 at 16:49
  • it categorises the rows in columns A, B and C. The functions in E then sum the values in columns A and C which are red (E2) or green (E3)
    – darasd
    Jan 2, 2014 at 17:45
  • So in column E, you would want to see as many values as there are distinct colours in column F, in the order they appear in column F? I'm not sure this is the optimal way to achieve what you're trying to do here. I think you may be better to have a data table on one sheet, and a pivot table on another that references your data table. Then you can slice and dice by colour/column name however you want.
    – Andi Mohr
    Jan 3, 2014 at 11:23
  • yes, i do want a value for each category, but i fully expect to use different formulas for each of these. once one is working for one category, it is easy to do the others.
    – darasd
    Jan 3, 2014 at 14:51

1 Answer 1

2

If I've understood you correctly, I don't think SUMIF is the way to go.

I'd add a helper column in between your D & E, like this:

A   B   C   D   E   F
1   4   7   A   x   30
2   5   8   C   x
3   6   9       x

In column E, where I've added 'x' as a placeholder, enter this formula (in cell E2 and copy down):

=IFERROR(SUM(INDIRECT(D2&":"&D2)),0)

This simply sums the totals for each column you specify in column D as your criteria. Where there is no criteria for that row you have the fallback 0 called by IFERROR.

Finally in cell F2 you can sum all those subtotals:

=SUM(E:E)

Your final table will look like this:

A   B   C   D   E   F
1   4   7   A   6   30
2   5   8   C   24
3   6   9       0
2
  • I think you misunderstood my suggestion of using SUMIF, so I've added a further example. Your solution will work, but I will need an extra column for each category under which I want to filter.
    – darasd
    Jan 2, 2014 at 16:12
  • This is a great solution for your situation @darasd. The only issue with your requirements is that you can't sum based on color without VBA. Jan 3, 2014 at 18:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .