• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Calculate Total needed to Order

Eddie Estrella

New Member
Good Afternoon,
I having been trying to create a macro that would take the On Hand balance (Col. O) and subtract itself from the months of demand (Cols. B:N) while leaving zeros where it is used and updating the balance each time until it reaches the last month. For example:
On hand = 100, Demand for Jul is 50. So it would subtract 50 from the On Hand making the demand 0 and reduce itself to 50 and continue on to the last month. The On Hand balance can be a negative number as that will tell me the quantity I need to order.

I can't think of anything to do this and I'm not sure it's even possible. I've attached a sample file of what I am looking at.

Thank you!
 

Attachments

  • Sample.xlsm
    100 KB · Views: 9
specifically for your sample file:
Code:
Sub blah()
For Each cll In Range("o2:o3").Cells
' cll.Select
  onhand = cll.Value
  For ofset = -12 To -1
    With cll.Offset(, ofset)
    ' .Select
      demand = .Value
      .Value = demand - Application.Median(demand, onhand, 0)
      onhand = onhand - demand
    End With
  Next ofset
  cll.Value = onhand
Next cll
End Sub
 
For example:
On hand = 100, Demand for Jul is 50. So it would subtract 50 from the On Hand making the demand 0 and reduce itself to 50 and continue on to the last month. The On Hand balance can be a negative number as that will tell me the quantity I need to order.
Isn't it just
Code:
Sub test()
    Dim r As Range
    For Each r In Range("o2", Range("o" & Rows.Count).End(xlUp))
        r.Value = r.Value - Application.Sum(r.EntireRow.Range("c1:n1"))
        r.EntireRow.Range("c1:n1").Value = 0
    Next
End Sub
?
 
Back
Top