Random Number Array - Select with criteria

Steviemac

New Member
Joined
May 24, 2021
Messages
14
Office Version
  1. 2019
Platform
  1. 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
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,214,923
Messages
6,122,283
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top