Somewhere off to the right where you aren't looking use eight columns.
In each, use terms along the lines of IF(F3=1,D3,0) [If F3=1, value from D3, else 0]
Then put a SUM term at the top of each column.
Then somewhere more convenient just X-ref to that sum cell.
G