View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Fill with random numbers


Get the code for UniqueRandomLongs from
www.cpearson.com/Excel/RandomNumbers.aspx. This will create a
1-dimensional array with no-repeating random numbers. Then, use that
code in

Sub AAA()
Dim Arr As Variant
Dim Arr2(1 To 200, 1 To 8) As Long
Dim R As Long
Dim C As Long
Dim N As Long
N = 0
Arr = UniqueRandomLongs(1, 1600, 1600)
For R = 1 To 200
For C = 1 To 8
N = N + 1
Arr2(R, C) = Arr(N)
Next C
Next R
Range("A1:H200").Value = Arr2
End Sub

This code converts the 1D array from UniqueRandomLongs to a 2D array
and then puts that array into A1:H200.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Wed, 11 Mar 2009 12:09:25 -0700, Dave
wrote:

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