Hi Xia Keshan, Thanks for your help. I do like your approach, however it doesn't work in all cases (I probably should have given different/extra examples). On few occasions I have a partial refund (in this case I'd like the refund to be deleted, the amount of the refund taken away from the closest positive amount within the number), refund which is a sum of previous payments and sum of two refunds is an amount. Oh and where I say refund I mean negative amount. Easier to explain on the below example. Is there a way of amending your code so it considers all below cases? (thanks again!!!) I don't need to keep obs, it is here only for explanation purposes. OBS Number amount count 1 1 45 1 2 1 -45 2 3 1 45 3 4 2 30 1 5 2 25 2 6 2 -30 3 7 2 25 4 8 3 50 1 9 3 60 2 10 3 -17 3 11 4 100 1 12 4 100 2 13 4 100 3 14 4 -200 4 15 5 80 1 16 5 40 2 17 5 -20 3 18 5 -20 4 And I'd like the results to be: OBS Number amount 1 1 45 5 2 25 7 2 25 8 3 50 1 9 3 43 2 /************************************ partial refund 60-17=43************************/ 11 4 100 1 /****************************** obs 12,13 cancel out obs 14***************************/ 15 5 80 1 /******************************obs 16 cancel out obs 17 and 18***************************/ ; Thanks for you help!
... View more