# Sum column cells until specified value is reached

#### NicoleO

##### New Member
Hi Guys,

I need some help with the below formula.

I was develop to sum horizontally and I cat seem to change it to work vertically.

=LOOKUP(H2,SUBTOTAL(9,OFFSET(A2,,,,COLUMN(\$A\$1:\$G\$1))))

Lookup value should be based n b12

#### Attachments

• 10.7 KB Views: 6

#### bosco_yip

##### Excel Ninja
Maybe,

=LOOKUP(B12,SUBTOTAL(9,OFFSET(B5,,,ROW(B\$5:B\$11)-ROW(B\$4))))

Regards

#### Peter Bartholomew

##### Well-Known Member
Wow. The original formula is full of functions that I rarely use [LOOKUP, SUBTOTAL, OFFSET, ROW] and don't really understand why it should work.
I did get to
Code:
``=LOOKUP(B\$12,SUBTOTAL(9,OFFSET(B\$5,,,ROW(\$A\$5:\$A\$11)-4,)))``
@bosco_yip Can you explain why an array of overlapping ranges does not throw an error?

If I were writing the formula for myself I would go with
Code:
``````= LOOKUP(limit,
SCAN(0,values,
LAMBDA(acc,val,acc+val)
)
)``````
LOOKUP earned its keep in place of XLOOKUP!