View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Rnd (Random) in VBA

I got too cute and forgot that the implicit conversion rounds the number.
Try it this way.

Sub GenRand()
Dim lngNum As Long
Dim i As Long
Range("B2:B200").ClearContents
i = 2
Do
lngNum = Int(Rnd() * 6 + 1)
Cells(i, 2).Value = lngNum
i = i + 1
Loop While lngNum = 6
Next j
End Sub

--
Regards,
Tom Ogilvy


"Paul LaPlant" wrote in message
...
Thanks for the quick replies. Tom, yours did the trick. The only thing
I changed was to adjust
lngNum = Rnd() * 6 + 1
to
lngNum = Rnd() * 5 + 1.

This gives me my random between 1 and 6. The first method gave me up to
7.

This was great. As usual, you are a big help.

Paul



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