Creating Random Numbers

  • Thread starter Thread starter David Nagoda
  • Start date Start date
D

David Nagoda

Is there an easy way to do the following?

I have lists of numbers that range from 5000 to over
10,000, generally from 1 to 50 or 1 to 100 numbers. I
have created a macro that sorts these lists and gives me
the frequency of them. In a given list of say 5000
numbers from 1 to 50, not all the numbbers (1 to 50) are
there, and I'm only interested in certian percentages. I
have gotten to the point where I have these sorted the
way I need them. The next step is I need to fill an
array with random numbers from this list. So say I have
45 numbers from 1 to 50, of these I have sorted out 25
that I need to create an array of 5X20 random number from
the list. How could this be esily done with a formula
and/or Macro?

Much thanks for any help on this,

David Nagoda
 
Try this. assumes 25 numbers are in "Sheet1" first column. Results to
"Sheet2". :-

'--------------------------------------------
Option Base 1
Sub TEST()
Dim Myarray(25)
Dim FromRange As Range
Dim ToRange As Range
Dim RandomNo As Integer
'-----------------------
'- stuff array from worksheet
Set FromRange = Worksheets("Sheet1").Range("A1:A25")
For R = 1 To 25
Myarray(R) = FromRange.Cells(R, 1).Value
Next
'--------------------------------------
'- random array to range
Set ToRange = Worksheets("Sheet2").Range("A1:T5")
For Each C In ToRange.Cells
RandomNo = Int(Rnd * 25) + 1
C.Value = Myarray(RandomNo)
Next
End Sub
'------------------------------------------------------
 
Back
Top