Reputation:
I am trying to create random numbers in within normal distribution given random probabilities in a range. My code is the following:
Range(Cells(2, 1), Cells(RandomNumbers + 1, 1)) = WorksheetFunction.Norm_S_Inv(Rnd)
Where RandomNumbers
is just a value in another cell. The problem is that if RandomNumbers
is equal to, lets say, 10 then VBA
fills the same random number in all 10 cells. How do I make every number different in every cell?
Upvotes: 1
Views: 94
Reputation: 351403
Make it a loop:
Dim cell as Range
For Each cell In Range(Cells(2, 1), Cells(RandomNumbers + 1, 1))
cell.Value = WorksheetFunction.Norm_S_Inv(Rnd)
Next
Upvotes: 2