Hi all,
I have a list of data:
Apple 580
Pear 245
Orange 867
Cherry 870
etc.
What I want to do is split my inventory between 5 locations randomly, but will only ever total the total inventory and then have VBA print the array so that it's like the following:
Apple 156
Apple 142
Apple 52
Apple 68
Apple 162
etc.
I have done this in excel, but very manual generating 5 random numbers then divide the random number by the Sum of 5 random numbers so that I get 100% the multiplying each % by the total number of apples and so on.
Excel Formula:
=(RANDOM NUMBER/SUM(RANDOM NUMBERS 1-5))*Inventory
To avoid all the decimals I'm rounding the numbers and row 5 is the total inventory - sum of 4 so that I wont have +-1 either side due to decimals
I have the following snippet to make the random numbers :
Anybody got an hints how I should approach this, I would presume some kind of array with loops i.e. row 1 calculate row 5 inventory then row 2 etc. and then print all the values to a new sheet.
I have a list of data:
Apple 580
Pear 245
Orange 867
Cherry 870
etc.
What I want to do is split my inventory between 5 locations randomly, but will only ever total the total inventory and then have VBA print the array so that it's like the following:
Apple 156
Apple 142
Apple 52
Apple 68
Apple 162
etc.
I have done this in excel, but very manual generating 5 random numbers then divide the random number by the Sum of 5 random numbers so that I get 100% the multiplying each % by the total number of apples and so on.
Excel Formula:
=(RANDOM NUMBER/SUM(RANDOM NUMBERS 1-5))*Inventory
To avoid all the decimals I'm rounding the numbers and row 5 is the total inventory - sum of 4 so that I wont have +-1 either side due to decimals
I have the following snippet to make the random numbers :
Code:
Sub Number()
Dim RandomNumber1 As Integer
Dim RandomNumber2 As Integer
Dim RandomNumber3 As Integer
Dim RandomNumber4 As Integer
Randomize
LRandomNumber1 = Int((100 - 0 + 1) * Rnd + 0)
LRandomNumber2 = Int((100 - 0 + 1) * Rnd + 0)
LRandomNumber3 = Int((100 - 0 + 1) * Rnd + 0)
LRandomNumber4 = Int((100 - 0 + 1) * Rnd + 0)
End Sub
Anybody got an hints how I should approach this, I would presume some kind of array with loops i.e. row 1 calculate row 5 inventory then row 2 etc. and then print all the values to a new sheet.