alexaronson
Active Member
- Joined
- Sep 30, 2005
- Messages
- 314
Hello and thank you for your time.
I need some help to speeding this For loop up.
Currently, if lastRow = 1,000, the macro is staking 97 secondes to complete. However, my lastRow has a value of around 43,000 cells meaning this macro would take about 69 minutes to complete. Right now, the inner For loop is 4 iterations long but will be expanding to 15 iterations in the future.
If I go an manually create the logic in excel and copy and paste it, it only takes me 2 minutes to get the answer which tells me something is just not right with this code.
Any Suggestions on how to speed it up?
I need some help to speeding this For loop up.
Currently, if lastRow = 1,000, the macro is staking 97 secondes to complete. However, my lastRow has a value of around 43,000 cells meaning this macro would take about 69 minutes to complete. Right now, the inner For loop is 4 iterations long but will be expanding to 15 iterations in the future.
If I go an manually create the logic in excel and copy and paste it, it only takes me 2 minutes to get the answer which tells me something is just not right with this code.
Any Suggestions on how to speed it up?
Code:
For i = i To lastRow
a = 1
Demand = wsDMDD.Cells(i, 5) + wsDMDD.Cells(i, 6)
FreeStock = wsDMDD.Cells(i, lastColumn + 2)
For a = a To lastColumn - 5
Select Case FreeStock
Case 0
wsDMDD.Cells(i, lastColumn + 2 + a) = Demand
Case Is > 0
If FreeStock > Demand Then
wsDMDD.Cells(i, lastColumn + 3) = 0
FreeStock = FreeStock - Demand
Demand = 0
End If
If FreeStock < Demand Then
Demand = Demand - FreeStock
FreeStock = 0
wsDMDD.Cells(i, lastColumn + 2 + a) = Demand
End If
End Select
Demand = wsDMDD.Cells(i, 6 + a)
Next
FreeStock = 0
Next