I would like to know if it is possible to reference a cell in Excel depending on the value of another cell.

Example

  • I have a cell, let's say A1 where I have the row number that I want to use (e.g., the content of A1 is 42)

  • I want to compute the sum of column B from row 1 to the row corresponding to the number given in A1. Something like =SUM( B1:B<NUMBER_IN_A1> )

Is there any way?

link|improve this question
feedback

2 Answers

up vote 2 down vote accepted

Use & to create the cell coordinates, access them using INDIRECT().

=SUM(INDIRECT("B1:B" & A1))
link|improve this answer
Thanks, exactly what I was looking for :-) – Matteo Feb 6 at 8:07
feedback

INDEX is normally preferable to INDIRECT where possible - because you don't have to "hardcode" the column and because it's not (as) volatile.

=SUM(B1:INDEX(B:B,A1))

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.