Hi,
There may be a smarter way but I simulated your example and by using SUMIF() based on criteria on col A, this achieved the result. i.e.
=SUMIF(A1:A100,A1,E1:E100)-SUMIF(A1:A100,A1,C1:C100).

You can of course change the criteria to whatever you need.

Stu