Hello! I think it would be so much easier to use the SUMIF Function
in excel for a conditional sum of values.
The way to use SUMIF is:
=SUMIF(range, criteria, sum_range)
range - range of where you will check the critiera
criteria - the condition where you will check whether to add the value
sum range - the range to be summed based on the condition
So it will easily add all values based on the condition you set. Hope this helps!