user10525226
user10525226

Reputation:

Random number with VBA

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

Answers (1)

trincot
trincot

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

Related Questions