Forum Discussion
wayne gasson
Oct 25, 2018Copper Contributor
VBA Random Number
Hi All,
I have created a Random Number Generator using the code below
Private Sub CommandButton1_Click()
Range("d2") = WorksheetFunction.RandBetween(-2, 2)
Range("d3") = WorksheetFunction.RandBetween(-2, 2)
which works exactly how I want it to
What I would like to do from here is generate a second button code to produce a 2nd random number using the first rand number as it's lowest value - but the code I thought would work doesn't - can anyone help please.
The code I used:
Range("f2") = WorksheetFunction.RandBetween(D2, 2)
Range("f3") = WorksheetFunction.RandBetween(D3, 2)
You may consider the following:
Range("F1") = WorksheetFunction.RandBetween(-2,2) ' The first random number
k = Range("F1")
Range("F2") = WorkhseetFunction.RandBetween (k,2)
' The second random number which lower bound depends on the previous random numberHop it helps.
- Man Fai ChanIron Contributor
You may consider the following:
Range("F1") = WorksheetFunction.RandBetween(-2,2) ' The first random number
k = Range("F1")
Range("F2") = WorkhseetFunction.RandBetween (k,2)
' The second random number which lower bound depends on the previous random numberHop it helps.
- wayne gassonCopper ContributorThank you I will give it a try :)