A1 has ref numbers
B1 has ref numbers
c1 has amount paid.

So if a1 matches the ref number in b1 then paste in e1 the total amount paid which will be in c1 if it does not match then leave it blank..