So I have two columns on named program and one with cost values. The three programs are ABC, A, B, and C. I want to sum the costs of all programs that contain A. All that contain B. And all that contain C. ABC clearly is included in all the sums. The problem is that to get just these programs the spreadsheet has a filter on it which messes sumif up. Can someone help? Here is an example of what I mean:
program cost
A 5.00
B 4.00
ABC 9.00
A 2.00
so I would want in three separate cells “sum with A”=16.00, “sum with B”=13.00, “sum with C”=9.00.
Assuming your above range is in A1:B5, my first formula is the following Array formula:
You create an Array formula by entering the formula and holding down the
Ctrl+Shiftkeys while you hit Enter. In my solution, I’ve created an area where I calculate by totals and have a column (called Item in this case) which indicates the letter I see in the original A column.If you were trying to enter this using VBA, you would use the
FormulaArrayproperty:Update
Restricting the calculation to only visible cells is a bit more complicated. Suppose we have your original data in cells A1:B5. Let’s also suppose our test values start in cell C7 (diagonal to the source data). Our totals formula would look like:
The following portion returns a range over the cells
This portion returns 1 for each visible cell and 0 for invisible cell
This portion is our criteria.
NOT(ISERROR(...will return TRUE or FALSE. The double negative sign--converts that value into a negative integer and then removes that negation.Lastly, the
SUMPRODUCTfunction multiplies the matching arrays to each other and executes the sum. The first two arrays return a series of 0’s or 1’s. If the row is both visible and matches our criteria, then we get 1*1 multipled by the given value in the cell. If the given cell is not visible or does not match the criteria, one of the two return a zero and it zeroes out the entire item.