Using your posted example, this formula sums from A10 through the number of cells indicated by D10
=SUM(A10:INDEX(A10:A20,D10))
Is that something you can work with?