Yes, thanks. In P18 copied down:

=IF(B18<>"",SUM(OFFSET($O18,0,0,MATCH("*",$B19:$B$53,0)+1)),"")

Adjust the reference in res for the maximum number of rows you might need.