Changing cell reference for a SUMIF criterion?

跟風遠走 提交于 2019-12-13 02:05:14

问题


I'm trying to tell Excel to change the cell reference for a SUMIF formula based on the last cell that contains a value in each row. Right now, I know I could write a nested if statement to do this for me, but it's far too unwieldy to be a long-term solution.

Example:

On a separate report, every person in this list has multiple lines recording their daily sales. On a small scale, I'd simply write a SUMIF that uses for A2, B3 and C4 as criteria. The scale is much much larger, so my current solution is to write out a logic check with the SUMIF formula folded into it.

In this case, the formula in E2 would be:

=IF(C2="",if(B2="",SUMIF('range',A2,'range'),sumif('range',B2,'range')),sumif('range',C2,'range'))

Is there a different way to tell Excel to run the SUMIF with the last value found in each row?

I was hoping I could use COUNTA for each row, then have the SUMIF formula use the COUNTA value to change the criterion cell reference. I'm missing something here.


回答1:


=SUMIF('range',INDEX(A2:C2,MATCH("zzzzz",A2:C2)),'range')

seems worth a try.

Edit Too long for a comment:

I don’t really have any idea how =MATCH() works but think of it as traversing left to right while searching. When it fails to find a match it just happens to have been looking at the last entry and (conveniently!) offers that up. So the key is to look for something that won't be found.

For people’s names I chose “zzzzz” as unlikely to be present. For numbers anything up to 9.99999999999999E+307 is theoretically possible and hence some people use that (eg an hour ago Formula to get the first cell with a numerical value from a selection?) but I prefer a googol (1E+100) and that seems quite large enough, is much shorter – and easier to remember, even if a few 9s more or less would make no difference, nor likely what couple of integers are after the +.



来源:https://stackoverflow.com/questions/18752640/changing-cell-reference-for-a-sumif-criterion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!