@jorgebeto16
I have come up with the below code that I believe will serve your purposes:
Sub allocate()
Dim equal_count As Integer
Dim remainder As Integer
For rw = 1 To Range("A2", Range("A1").End(xlDown)).Rows.Count
equal_count = Application.WorksheetFunction.RoundDown(Cells(rw + 1, 1).Value / 5, 0)
remainder = Cells(rw + 1, 1) - (equal_count * 5)
Range(Cells(rw + 1, 2).Address, Cells(rw + 1, 6).Address).Value = equal_count
If remainder <> 0 Then
For demand = 1 To 5
If Cells(rw + 1, demand + 9) >= 6 - remainder Then
Cells(rw + 1, demand + 1) = Cells(rw + 1, demand + 1) + 1
End If
Next demand
End If
Next rw
End Sub
This should accurately perform what you want. I have tested this in my own workbook and the results seem correct:
Priority Allocation.PNG
As a note this particular code would need to be ran after every change to your data set. Other sources would enable you to utilize automation based on cell changes, etc. Please let me know if this is not close enough to be adapted to your immediate needs.
Thanks,
DarkF1ame
P.S. - If this does indeed resolve your issue please mark this thread as "Solved".
Bookmarks