Steviemac
New Member
- Joined
- May 24, 2021
- Messages
- 14
- Office Version
- 2019
- Platform
- Windows
Cobbled an array together, but could do with a bit of adjustment help please
It picks the first random number (between 1 & 15) then
picks the second random number based on being bigger than the first up to the upper limit (20) then
picks the third random number based on being bigger than the second up to the upper limit (25) then
picks the fourth random number based on being bigger than the third up to the upper limit (30) then
picks the fifth random number based on being bigger than the fourth up to an upper limit (35)
Would it be possible the change the code so there would be a lower limit aswell?
E.G.
Group5 value would be greater than the Group4 value and greater than the "Lower" of "x" limit and Less than the upper limit of 30
(the limits will be changed every now and then when Group memebers change as this is part of a larger macro)
Thanks
Sub RandwithUpperLowerLimits()
ArrRows = 56
ArrCols = 5
ReDim TeamArray(1 To ArrRows, 1 To ArrCols)
For Team1 = LBound(TeamArray, 1) To UBound(TeamArray, 1)
TeamArray(Team1, 1) = Int((15 * rnd) + 1)
TeamArray(Team1, 2) = Int(TeamArray(Team1, 1) + 1 + rnd * (20 - TeamArray(Team1, 1)))
TeamArray(Team1, 3) = Int(TeamArray(Team1, 2) + 1 + rnd * (25 - TeamArray(Team1, 2)))
TeamArray(Team1, 4) = Int(TeamArray(Team1, 3) + 1 + rnd * (30 - TeamArray(Team1, 3)))
TeamArray(Team1, 5) = Int(TeamArray(Team1, 4) + 1 + rnd * (35 - TeamArray(Team1, 4)))
Next Team1
ActiveSheet.Range("AI2").Resize(ArrRows, ArrCols).Value = TeamArray
End Sub
It picks the first random number (between 1 & 15) then
picks the second random number based on being bigger than the first up to the upper limit (20) then
picks the third random number based on being bigger than the second up to the upper limit (25) then
picks the fourth random number based on being bigger than the third up to the upper limit (30) then
picks the fifth random number based on being bigger than the fourth up to an upper limit (35)
Would it be possible the change the code so there would be a lower limit aswell?
E.G.
Group5 value would be greater than the Group4 value and greater than the "Lower" of "x" limit and Less than the upper limit of 30
(the limits will be changed every now and then when Group memebers change as this is part of a larger macro)
Thanks
Sub RandwithUpperLowerLimits()
ArrRows = 56
ArrCols = 5
ReDim TeamArray(1 To ArrRows, 1 To ArrCols)
For Team1 = LBound(TeamArray, 1) To UBound(TeamArray, 1)
TeamArray(Team1, 1) = Int((15 * rnd) + 1)
TeamArray(Team1, 2) = Int(TeamArray(Team1, 1) + 1 + rnd * (20 - TeamArray(Team1, 1)))
TeamArray(Team1, 3) = Int(TeamArray(Team1, 2) + 1 + rnd * (25 - TeamArray(Team1, 2)))
TeamArray(Team1, 4) = Int(TeamArray(Team1, 3) + 1 + rnd * (30 - TeamArray(Team1, 3)))
TeamArray(Team1, 5) = Int(TeamArray(Team1, 4) + 1 + rnd * (35 - TeamArray(Team1, 4)))
Next Team1
ActiveSheet.Range("AI2").Resize(ArrRows, ArrCols).Value = TeamArray
End Sub