View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Colin Colin is offline
external usenet poster
 
Posts: 86
Default Rand between 1 and 50


Thank you for all your responses,

Colin.


"Mike H" wrote:

There are no VB ways of getting unique randoms


Which should have been There are non VB ways.......

"Mike H" wrote:

Colin,

There are no VB ways of getting unique randoms within a range but here's a
VB solution you may consider, right click your sheet tab view code and paste
this in and run it. It will put 6 unique numbers in columnA

Sub Lottry_Randoms()
Dim MyRange As Range
Set MyRange = Range("A1:A6")
For Each c In MyRange
Do
c.Value = Int((50 * Rnd) + 1)
Loop Until WorksheetFunction.CountIf(MyRange, c.Value) < 2
Next
End Sub

Mike

"Colin" wrote:

I have a lottery worksheet to design which will produce 6 unique numbers
between 1 and 50 in six cells.
I use =INT(RAND()*51) at the moment which works well. How do I alter this
function so that 0 does not appear as one of the numbers?
--
Thank you,

Colin.