Cell D2:and copy down.Formula:
=IF($B2<>"","",SUM(INDEX($B:$B,ROW($A2)+1):INDEX($B:$B,ROW($A2)+$C2)))
Or
Cell D2:Formula:
=IF(ISNUMBER($C2),SUM(INDEX($B:$B,ROW($A2)+1):INDEX($B:$B,ROW($A2)+$C2)),"")
Variations on a theme depending on your data structure.
See the updated example attached
Bookmarks