Random selections

alexv

New Member
Joined
Jun 26, 2006
Messages
27
I have a data in an excel sheet from column A to column L that is 10 rows long. I want to randomly pick data from 20 cells. I have searched the postings with not much luck. Any help?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi alexv

Please try:

=INDEX($A$1:$L$10,1+INT(RAND()*10),1+INT(RAND()*12))

Hope this helps
PGC
 
Upvote 0
Thank you.

I also would like for it to ignore the empty cells in the table so that my random sample will not include any blank values. Is there a way to do that?
 
Upvote 0
Hi alexv

This is one possible solution.
This code writes in N1:N20 20 numbers taken randomly out of the non-empty cells in A1:L10

You can assign it to a Command Button to generate a different list each time you click on it.

Hope this helps
PGC

Code:
Sub PickRandNumbers()
Dim rCell As Range, dNumber(1 To 120) As Double, iMax As Integer, i As Integer

For Each rCell In Range("A1:L10")
    If rCell <> "" Then
        iMax = iMax + 1
        dNumber(iMax) = rCell
    End If
Next

For i = 1 To 20
    Range("N" & i) = dNumber(1 + Int(Rnd() * iMax))
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,217
Messages
6,123,673
Members
449,116
Latest member
HypnoFant

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