Can the extent of a range be altered by a variable?

Is it possible to change the extent of a range entered as an argument in a function dependant on the contents of another cell?

For example, can a SUM function be written so that it evaluates SUM(A1:A3) if the content of a cell, say B1, is 3, or SUM(A1:A6) if B1 contains 6?

Apologies if this is a silly question and the answer is obvious!

1 Like

Hallo

=SUM(A1:INDEX(A:A;$B$1))
5 Likes

Thank you! :slight_smile:

You may also try the systematically very clear =SUM(OFFSET(A1;0;0;B1;1))The first two “0” behind the “A1” simply tell that you actually want to start with cell A1 (not including an offset “right of” or “below”). Th B1 then gives the reference to the cell where to look for the number of rows to be included, and the following fix “1” then says “just one column”.
There is a help page for OFFSET(), of course.

4 Likes

Thank you! :slight_smile: