Find row number of sum result in range

喜欢而已 提交于 2021-01-01 09:05:10

问题


I'm breaking my head on the following:

I have 15 as a lookup value in B1

In A1:A4 for each cell the value is 5. (I real these are all different values).

I want excel to SUM the values of A1:A4 one by one and if the search value is reached by that sum, return the row number. So for this example I want result 3 (=5+5+5) If no exact match then return the closest match smaller than the search value.

I tried something like =MATCH(1,B1=SUM(A1:A4),1) which doesn't work obviously, but I don't know if it's even possible without VBA. Does anybody know a way (without helper column).


回答1:


You may try:

=MATCH(TRUE,--SUBTOTAL(9,OFFSET(A1:A4,,,ROW(A1:A4)))>=B1,0)

I'm using Excel O365, but any other version may need CSE-entering of the above (I'm unsure). Do note OFFSET() is volatile!

The above would return the row where the cumulative sum first >=B1. If your goal as per your question was to get the closest match but smaller than B1 in case there is no exact match:

=MATCH(B1,--SUBTOTAL(9,OFFSET(A1:A4,,,ROW(A1:A4))))


来源:https://stackoverflow.com/questions/65454974/find-row-number-of-sum-result-in-range

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