possible until 5461

T

tom taol

sub ex()
n = 5462

ReDim aRnd(1 To n)
ReDim uniq(1 To n)

For i = 1 To n: aRnd(i) = i: Next

For i = n To 2 Step -1
k = Int(Rnd * i) + 1
n_cnt = n_cnt + 1
uniq(n_cnt) = aRnd(k)
aRnd(k) = aRnd(i)
Next

uniq(n) = aRnd(1)
Range("b1:b" & n).Value = Application.Transpose(uniq)
end sub

why error?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
T

Tom Ogilvy

Faster and simpler than transposing or using Alan's code would be

sub ex()
n = 5462

ReDim aRnd(1 To n)
ReDim uniq(1 To n, 1 to 1)

For i = 1 To n: aRnd(i) = i: Next

For i = n To 2 Step -1
k = Int(Rnd * i) + 1
n_cnt = n_cnt + 1
uniq(n_cnt,1) = aRnd(k)
aRnd(k) = aRnd(i)
Next

uniq(n,1) = aRnd(1)
Range("b1:b" & n).Value = uniq
end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top