I am complete rookie to VBA, but i have been attempting to write a macro that can generate a list of productions ID's that are fit for production, based on two parameters. A production can only be initiated if it can be produced 100%, no split production is allowed, and the current stock of the part to be produced need to be less than 20% of a years sales.
I have written the following code, which does do what i want it to, but i know it can be written smarter, and with dynamic arrays, cause i never know the excact amount of produciton orders to look through, and how many can be singled out for production.
Sub LavProduktionsListe()
Dim lngProduktionsID(1 To 125) As Long 'ProduktionsID variabel array
Dim curProducerbar(1 To 125) As Currency ' Producerbar variabel array
Dim curStockPct(1 To 125) As Currency ' Lager procent variabel array
Dim i As Long ' Row count
i = 1
With Sheets("Oversigt")
Application.ScreenUpdating = False
Do Until IsEmpty(.Cells(i + 1, 1)) = True
lngProduktionsID(i) = .Cells(i + 1, 1).Value
curProducerbar(i) = .Cells(i + 1, 4).Value
curStockPct(i) = .Cells(i + 1, 6).Value
If curProducerbar(i) = 1 And curStockPct(i) < 0.2 Then 'If it is possible to produce 100% of a produciton order, and current stock is less than 20% of 12 months sales
Range("I2500").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select 'Select first empty cell in column I
ActiveCell = lngProduktionsID(i) ' Write production ID
End If
i = i + 1 'Next row
Loop
Application.ScreenUpdating = True
End With
End Sub
I have attached a sample sheet of how my excel sheet with production overview looks like. Can someone help me rewrite the code to use dynamic arrays? And please make comments as to what is what and so on, so I can learn. Useful articles and guides to dynamic arrays are also more than welcome to be shared, so can nail this VBA programming eventually.
Bookmarks