Split values among relevant columns field

  • What do you mean by

    I need it line wise

    Are the values in Column D the required result? If so, then what is the logic to get those results?

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • OK I worked out the logic.


    Try the attached file, click the button on the sheet.


    Code assigned to the button:

  • Thanks for your quick response.


    The each lines should be intact/line wise i.e if input contains 100 rows I need required value column "d" for all 100 rows.


    The logic for Required colum "D" is


    A. The Gross qty of A, b, c, d, e, f, and G are 30,77,98,34,180,10 and 22 respectively.


    1. Gross qty "A" of 30 should meet from line qty of "A" from 12 & 23. In meeting so,12 will get "exhausted" first and column"d" goes blank, then goes to 23 and from 23, only 18 will get "exhausted" from it and the remaining 5 is placed in column"d" against the row containing line qty 23.


    2. Gross qty "b" of 77 should meet from line qty of "b" from 45,30, & 2. In meeting so, 45 will get "exhausted" first, then 30 gets "exhausted" and 2 gets "exhausted" from line qty and there is no remaining column"d" against all rows containing "b".


    3. Gross qty "G" of 22 should meet from line qty of "G" from 30 & 30. In meeting so, 22 will get "exhausted" first, the remaining 8 is placed in column"d" against the row containing line qty 30. since we have exhausted gross qty from ""B17", the next 30 in "B18" goes to column"d" without any deduction.


    Hope I am able to explain the logic. Still looking for formula/VBA code.


    Thanks

  • You're welcome

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Just realised the code will fail if the Item in Column A is an Item with just a single row.


    Change the code to what is shown below to overcome this.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • So to get the Revised Quantity the Line Quantity of the last entry for each Item is reduced by the Required Quantity?

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Probably easiest to do it with a formula, put this in E2 and copy down:


    =IF($D3="","",IF(ROW(A3)<3,IF(IF(D3<>"-",B3-$D3,B3)<0,0,IF(D3<>"-",B3-D3,B3)),IF(AND(A3<>A2,A3=A4),IF(IF(D3<>"-",B3-D3,B3)<0,0,IF(D3<>"-",B3-$D3,B3)),IF(AND(A3=A2,A3=A4),IF(OR(E2=C2,E2=0),0,IF(IF(D3<>"-",B3-D3,B3)<0,0,IF(D3<>"-",B3-D3,B3))),IF(IF(D3<>"-",B3-D3,B3)<0,0,IF(D3<>"-",B3-D3,B3))))))


    You will also need to make a small change to the VBA code.


    Change With Sheet1.Cells(1).CurrentRegion to With Sheet1.Cells(1).CurrentRegion.Resize(, 4)


    I am attaching the sample file with additional Items, Line Quantities and Gross Quantities so as to test for all possible scenarios. The Revised Line Quantity column has the above formula in it and the change to the code made, click the button as before.

  • You're welcome

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!