perfecting VBA

Status
Not open for further replies.

Jan Kalop

Active Member
Joined
Aug 3, 2012
Messages
389
This VBA formula is working perfectly, but I would like to be able control, the amount of numbers (in the case of bellow VBA formula is 28) to be random, from designated worksheet cell, for sample A1.
The same refers to choosing the Range (which in this sample is 6) to be able to control from designated worksheet cell, for sample B1.


"Sub TwentyfiveRandOf25ONLY6()
Dim anArray(1 To 28) As Long
Dim i As Long
Dim randIndex As Long, temp As Long
For i = 1 To 28
anArray(i) = i
Next i
For i = 1 To 28
Randomize
Do
randIndex = (Rnd() * 28) + 1
Loop Until randIndex <= 28
temp = anArray(randIndex)
anArray(randIndex) = anArray(i)
anArray(i) = temp
Next i
Range("aq8").Resize(, 6).Value = anArray
End Sub"




Is this possible to rearrange the VBA formula to achieve that, and how?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Assuming cell A1 is a value you can try

Dim myVal as integer
myVal = Range("A1").Value

Then replace all instances of 28 in your code with myVal
 
Upvote 0
@Jan Kalop

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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