Hi All,
I am creating and order form that adds items based on total need until we have a full truck. I have the form which pulls in the initial must purchase items as there are none on hand and calculates the total weight of the order. When the order does not meet the truck load the loop goes and adds 1 to the items with the lowest quantity on hand (identified with ranking on my raw data) then checks again to see truck space availability. Then loops until we reach weight needed. When I run this loop it is very fast and efficient.
I recently wanted to be able to include multiple store locations and just make the change to orderform and run the loop on my raw data. I added an IF and then statement to do this, but now the loop is very slow and sometimes does not always complete. Is there a faster way to do this? Below is the code:
I am creating and order form that adds items based on total need until we have a full truck. I have the form which pulls in the initial must purchase items as there are none on hand and calculates the total weight of the order. When the order does not meet the truck load the loop goes and adds 1 to the items with the lowest quantity on hand (identified with ranking on my raw data) then checks again to see truck space availability. Then loops until we reach weight needed. When I run this loop it is very fast and efficient.
I recently wanted to be able to include multiple store locations and just make the change to orderform and run the loop on my raw data. I added an IF and then statement to do this, but now the loop is very slow and sometimes does not always complete. Is there a faster way to do this? Below is the code:
VBA Code:
Sub Optomize_Order()
'Basic Parameters for entire code
'Set workbook and sheets
Dim Order_Op As Workbook
Set Order_Op = ThisWorkbook
Dim Order_Form As Worksheet
Set Order_Form = Order_Op.Sheets("Order_Form")
Dim Raw_Data As Worksheet
Set Raw_Data = Order_Op.Sheets("Raw_Data")
'Setting the goal
Set Weight = Order_Form.Range("A21")
'Setting the BU
Set BU = Order_Form.Range("G2")
'Setting Range to Adjust variable
Dim Amount As Range, cell_2 As Range
Set Amount = Raw_Data.Range("n1:n1500")
'Setting excess Ranking Range
Dim Excess As Range, cell As Range
Set Excess = Raw_Data.Range("q1:q1500")
'Loop until weight greater than 46200
Do While Weight <= 46200
If Weight.Value <= 46200 Then Raw_Data.Activate
StartRow = 1
LastRow = Cells.Find("*", Cells(1), xlFormulas, xlWhole, xlByRows, xlPrevious).Row
For Row = StartRow To LastRow Step 1
If Cells(Row, 17) = 1 And Cells(Row, 2) = BU Then
Cells(Row, 14) = Cells(Row, 14).Value + 1
Order_Form.Activate
End If
Next Row
Loop
End Sub