adding loop in VBA

Jan Kalop

Active Member
Joined
Aug 3, 2012
Messages
389
I have already VBA for random numbers, but I would like to add loop for how many times the random is run and the number foe sample is in Z25

"Sub TwentyfiveRandOf25()
Dim anArray(1 To 25) As Long
Dim i As Long
Dim randIndex As Long, temp As Long
For i = 1 To 25
anArray(i) = i
Next i
For i = 1 To 25
Randomize
Do
randIndex = (Rnd() * 25) + 1
Loop Until randIndex <= 25
temp = anArray(randIndex)
anArray(randIndex) = anArray(i)
anArray(i) = temp
Next i
Range("Aa1:aa25").Value = Application.Transpose(anArray)
End Sub"
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Maybe I add a bit more information:
That VBA function produce 25 numbers (without repeats ) in column AA1:AA25. Every time I click on the button to run that VBA the numbers are generated in unique way from 1 to 25 but not in ascending or descending order but randomly, but only once.
What I would like to happens is that every time I click on the button to run that VBA it is run as many time as is the number in cell Z25 and for sample it can be any number from 1 to 30, which mean that the random numbers would have to be run and generate Z25 times that unique set of numbers.
Is that possible to add any additional scrip to that existing VBA to make it happen?
Thanks everyone for help.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

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