I have 3 listboxes. The first one contains names, reference, and negative values. The second is structured the same way but with positive values. what I am trying to do is to loop through each row in listbox1 and check if the name exists in listbox2 and then if found distribute the negative value across the positive ones and put in listbox3
ListBox1
Name1, Ref1, -90
Name1, Ref2, -30
Name2, Ref3, -40
Listbox2
Name1, Ref4, 50
Name1, Ref5, 30
Name1, Ref6, 70
Listbox3
Name1, Ref1, Ref4, 50 'remaining value -90+50 = -40 .. remove item from listbox2
Name1. Ref1, Ref5, 30 'Remaining value -90+50+30 = -10 .. remove item from listbox2
Name1, Ref1, Ref6, 10 'Remaining value -90+50+30+10 = 0 .. Keep item in listbox2 but change the value from 70 to 70 - 10 = 60 or 50+30+70-90=60
then loop through the next item in listbox1 and do the same
ListBox1
Name1, Ref1, -90
Name1, Ref2, -30
Name2, Ref3, -40
Listbox2
Name1, Ref4, 50
Name1, Ref5, 30
Name1, Ref6, 70
Listbox3
Name1, Ref1, Ref4, 50 'remaining value -90+50 = -40 .. remove item from listbox2
Name1. Ref1, Ref5, 30 'Remaining value -90+50+30 = -10 .. remove item from listbox2
Name1, Ref1, Ref6, 10 'Remaining value -90+50+30+10 = 0 .. Keep item in listbox2 but change the value from 70 to 70 - 10 = 60 or 50+30+70-90=60
then loop through the next item in listbox1 and do the same