Thread: random numbers
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
tomic tomic is offline
external usenet poster
 
Posts: 12
Default random numbers

Thanks Gary.

Works Great.

The other responses look easy too...however, I got an unrecognized name
error. I'm using Excel 2003 - is randbetween a formula in 2007?



"Gary Brown" wrote:

'/=============================/
Sub Macro1()
Dim dbl As Double
Dim dblMax As Double
Dim dblRandNos As Double

'put random #s in row starting at Cell D1
Range("D1").Select

'clear Column D of old info
Range("D:D").ClearContents

'get values in C3 and C5
dblMax = Range("C3").Value2
dblRandNos = Range("C5").Value2

'create random #s
For dbl = 1 To dblRandNos
ActiveCell.Offset(dbl - 1, 0).Value = _
Int(Rnd() * dblMax) + 1
Next dbl

End Sub
'/=============================/

--
Hope this helps.
Thanks in advance for your feedback.
Gary Brown


"tomic" wrote:

I am trying to generate a list of random numbers based on the results in a
couple cells.

Cell C3 contains a number that is input by the user.

Cell C5 contains the results of a formula - related to the number in C3

I would like to create X number of random numbers, where X = C5, and all of
the random numbers must be integers between 1 and the value in cell C3

I've tried a few things based on some other posts, and using some sorting,
but haven't been able to do this successfully. Any help / suggestions would
be appreciated.

Thanks.