Google Sheets – Sum Cells Until a Certain Value is Reached

formulasgoogle sheets

I have a column with a list of numbers. I want to calculate the sum of the numbers, starting from the top until the value of sum reaches a fixed value, and then stop and return the cell address of the cell where the sum reached its limit. Is there a formula for this? If not, what would be the script for a custom formula?

Best Answer

Suppose your original numbers are in A2:A. This would return the cell address where the cumulative sum reached or exceeded 100:

=ArrayFormula(ADDRESS(VLOOKUP(TRUE,{SUMIF(ROW(A2:A),"<="&ROW(A2:A),A2:A)>=100,ROW(A2:A)},2,FALSE),COLUMN(A2)))

You can change the 100 to whatever target you like; or you can replace 100 with a cell address that contains a target value you enter.