I have this code, it gets the demand of a particular part no, search for a supply in another table and returns the order, date, quantity, supplier and coordinator.
I tested this on a smaller sheet and it works well, but on the sheet that I need this to run I have 30k plus lines on each table, so it takes a really long time to run,
Do you guys have a clue on how to solve this problem?
The part no´s on demand and supply are not unique, so I search for the first supply of that part no and subtract the demand from the supply amount.
I tested this on a smaller sheet and it works well, but on the sheet that I need this to run I have 30k plus lines on each table, so it takes a really long time to run,
Do you guys have a clue on how to solve this problem?
The part no´s on demand and supply are not unique, so I search for the first supply of that part no and subtract the demand from the supply amount.
VBA Code:
Sub Plan()
Dim rows_supply As Long
Dim array_pnsupply() As String, array_qtysupply() As Double, array_ordersupply() As String, array_datesupply() As Date
Dim srow As Long, drow As Long, pos As Long, dcol As Long
Dim demand As Double, supply As Double
rows_supply = WorksheetFunction.CountIf(Sheets("supply").Range("a:a"), "<>" & "") - 1
ReDim array_pnsupply(rows_supply - 1)
ReDim array_qtysupply(rows_supply - 1)
ReDim array_ordersupply(rows_supply - 1)
ReDim array_datesupply(rows_supply - 1)
ReDim array_suppliersupply(rows_supply - 1)
ReDim array_coordinatorsupply(rows_supply - 1)
srow = 2
Do While Sheets("Supply").Cells(srow, 1) <> ""
array_pnsupply(srow - 2) = Sheets("Supply").Cells(srow, 10)
srow = srow + 1
Loop
srow = 2
Do While Sheets("Supply").Cells(srow, 1) <> ""
array_qtysupply(srow - 2) = Sheets("Supply").Cells(srow, 12)
srow = srow + 1
Loop
srow = 2
Do While Sheets("Supply").Cells(srow, 1) <> ""
array_ordersupply(srow - 2) = Sheets("Supply").Cells(srow, 1)
srow = srow + 1
Loop
srow = 2
Do While Sheets("Supply").Cells(srow, 1) <> ""
array_datesupply(srow - 2) = Sheets("Supply").Cells(srow, 26)
srow = srow + 1
Loop
srow = 2
Do While Sheets("Supply").Cells(srow, 1) <> ""
array_suppliersupply(srow - 2) = Sheets("Supply").Cells(srow, 5)
srow = srow + 1
Loop
srow = 2
Do While Sheets("Supply").Cells(srow, 1) <> ""
array_coordinatorsupply(srow - 2) = Sheets("Supply").Cells(srow, 7)
srow = srow + 1
Loop
drow = 2
dcol = 13
Do While Sheets("Demand").Cells(drow, 7) <> ""
demand = Sheets("Demand").Cells(drow, 9).Value
supply = 0
pos = 0
Do While (pos <= rows_supply - 1) And (demand > 0)
If (Sheets("Demand").Cells(drow, 7) = array_pnsupply(pos)) And (array_qtysupply(pos) > 0) Then
supply = array_qtysupply(pos)
demand = demand - supply
If demand >= 0 Then
Sheets("Demand").Cells(drow, dcol) = array_ordersupply(pos)
Sheets("Demand").Cells(drow, dcol + 1) = array_qtysupply(pos)
Sheets("Demand").Cells(drow, dcol + 2) = array_suppliersupply(pos)
Sheets("Demand").Cells(drow, dcol + 3) = array_coordinatorsupply(pos)
Sheets("Demand").Cells(drow, dcol + 4) = array_datesupply(pos)
array_qtysupply(pos) = 0
Else
Sheets("Demand").Cells(drow, dcol) = array_ordersupply(pos)
Sheets("Demand").Cells(drow, dcol + 1) = array_qtysupply(pos) + demand
Sheets("Demand").Cells(drow, dcol + 2) = array_suppliersupply(pos)
Sheets("Demand").Cells(drow, dcol + 3) = array_coordinatorsupply(pos)
Sheets("Demand").Cells(drow, dcol + 4) = array_datesupply(pos)
array_qtysupply(pos) = -demand
End If
dcol = dcol + 5
End If
pos = pos + 1
Loop
drow = drow + 1
dcol = 13
Loop
MsgBox "Finished planning, you will be redirected to the analysis!"
End Sub