Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Generate Random Number Table

Howdy,

I would like to generate a random number in a named range. The named range
would have a variable size (up to 25000 row and 50 column). I know that I
can copy/paste RND() in all the cells, but I am interested in generating the
number. Using RND(), I would have to copy paste values so they would not
change. I am also concerned about looping that many times and how long that
would take.

Is there an easy way to essentially populate a 2-D array from a random
function?

Regards,
TB

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Generate Random Number Table

This will be fairly quick:

Public Sub FillNamedRangeWithRandoms()
Dim vArr As Variant
Dim i As Long
Dim j As Long
With Range("MyRange")
ReDim vArr(1 To .Rows.Count, 1 To .Columns.Count)
For i = 1 To UBound(vArr, 1)
For j = 1 To UBound(vArr, 2)
vArr(i, j) = Rnd
Next j
Next i
.Value = vArr
End With
End Sub


In article , Tim Bieri
wrote:

Howdy,

I would like to generate a random number in a named range. The named range
would have a variable size (up to 25000 row and 50 column). I know that I
can copy/paste RND() in all the cells, but I am interested in generating the
number. Using RND(), I would have to copy paste values so they would not
change. I am also concerned about looping that many times and how long that
would take.

Is there an easy way to essentially populate a 2-D array from a random
function?

Regards,
TB

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Generate Random Number Table

Hi Tim,

try:

For Each cell In Range("name")

cell.Formula = "=RND()"

Next cell


Thats even shorter ;o)

Best

Markus


-----Original Message-----
Howdy,

I would like to generate a random number in a named

range. The named range
would have a variable size (up to 25000 row and 50

column). I know that I
can copy/paste RND() in all the cells, but I am

interested in generating the
number. Using RND(), I would have to copy paste values

so they would not
change. I am also concerned about looping that many

times and how long that
would take.

Is there an easy way to essentially populate a 2-D array

from a random
function?

Regards,
TB

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Generate Random Number Table

and one more

Sub GenRandom()
With Range("MyRange")
.Formula = "=rand()"
.Formula = .Value
End with
End Sub
Doesn't require any looping and the numbers produced won't change.
Nonetheless, it may be slower than JE's solution depending on how
calculation gets involved. I don't know since I haven't tested it.

--
Regards,
Tom Ogilvy

"Tim Bieri" wrote in message
...
Howdy,

I would like to generate a random number in a named range. The named

range
would have a variable size (up to 25000 row and 50 column). I know that I
can copy/paste RND() in all the cells, but I am interested in generating

the
number. Using RND(), I would have to copy paste values so they would not
change. I am also concerned about looping that many times and how long

that
would take.

Is there an easy way to essentially populate a 2-D array from a random
function?

Regards,
TB



  #5   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 408
Default Generate Random Number Table

Howdy,

Thanks to all for the great responses.

In an unscientific test, both (Tom and JE) methods appear to be about equal,
if you turn off the screen update. They are pretty close to equal with
screens update on, with Tom's updating twice. Either way, they are less than
5 seconds for 25k x 50.

Regards
TB

"Tim Bieri" wrote:

Howdy,

I would like to generate a random number in a named range. The named range
would have a variable size (up to 25000 row and 50 column). I know that I
can copy/paste RND() in all the cells, but I am interested in generating the
number. Using RND(), I would have to copy paste values so they would not
change. I am also concerned about looping that many times and how long that
would take.

Is there an easy way to essentially populate a 2-D array from a random
function?

Regards,
TB




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
In excel, I want to generate a random number to the max Excel Discussion (Misc queries) 7 June 20th 07 07:49 PM
Generate random number from a list Arnie Excel Worksheet Functions 6 November 7th 06 07:55 AM
How do I generate only one random number without it refreshing? joshman Excel Worksheet Functions 5 June 21st 06 06:53 AM
generate a random number and use if function to generate new data Dogdoc1142 Excel Worksheet Functions 4 April 26th 06 03:44 AM
GENERATE RANDOM NUMBERS BUT EXCLUDE A NUMBER IN THE SEQUENCE Tracker Excel Discussion (Misc queries) 6 August 5th 05 02:49 AM


All times are GMT +1. The time now is 06:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"