Fill with random numbers
Here's one more...
Sub FillRangeWithRandomNumbers()
Dim R As Range
Dim X As Long
Dim Temp As Long
Dim RandomIndex As Long
Dim RandomNumbers() As Long
Const CellRange As String = "A1:H200"
ReDim RandomNumbers(1 To Range(CellRange).Count)
' Initialize the RandomNumbers array
For X = 1 To UBound(RandomNumbers)
RandomNumbers(X) = X
Next
' Randomize the RandomNumbers array
For X = UBound(RandomNumbers) To 1 Step -1
RandomIndex = Int((X - LBound(RandomNumbers) + 1) * _
Rnd + LBound(RandomNumbers))
Temp = RandomNumbers(RandomIndex)
RandomNumbers(RandomIndex) = RandomNumbers(X)
RandomNumbers(X) = Temp
Next
' Distribute the random numbers to the Range
X = 1
For Each R In Range(CellRange)
R.Value = RandomNumbers(X)
X = X + 1
Next
End Sub
--
Rick (MVP - Excel)
"Dave" wrote in message
...
Hi,
The range A1 - H200 is 1600 cells and I need to fill those cells randomely
with the numbers 1 to 1600, no number must repeat. I played with simply
putting those numbers in the cells and used RAND() in a helper column but
this doesn't really give the randomness I require. Any help please.
D
|