dimanche 2 mai 2021

How to generate random quantites until reach a certain number

"i want to generate random numbers (with limits for each case(item number)) until reach specific number (which is the sum of the total column) "

;this is a a daily sales list for a restaurant, I want to ask the code to generate quantities that will lead to specific totals sales, the unit price column is fixed

this code is working but i cant choose specific value to reach but i have to choose range, and the other problem is when th range difference is small the code take too much time to solve the problem and it still working ..."

table present code

Sub mad()

Do Until Range("A54").Value > Range("j54").Value And Range("A54").Value < Range("j55").Value

For i = 11 To 51
Select Case i
Case 12, 14, 15, 16, 33 To 36
'Small and medium meal'
Cells(i, 3).Value = Int((VBA.Rnd * 12) + 3)

Case 11, 13, 17, 37
'big meals'
Cells(i, 3).Value = Int((VBA.Rnd * 6) + 1)

Case 20 To 28
'sandwitches and snacks'
Cells(i, 3).Value = Int((VBA.Rnd * 4) + 1)

Case 29 To 32, 38 To 40, 45 To 47
'small snacks, potato, cheese'
Cells(i, 3).Value = Int((VBA.Rnd * 3) + 0)

Case 41
'cola 250 ml '
Cells(i, 3).Value = Int((VBA.Rnd * 15) + 1)

Case 42 To 44
'cola 1 & 2 ltr'
Cells(i, 3).Value = Int((VBA.Rnd * 4) + 0)

Case Else
'addtitions'
Cells(i, 3).Value = Int((VBA.Rnd * 3) + 0)
End Select



Next i

Loop

End Sub



Aucun commentaire:

Enregistrer un commentaire