generating a whole random # from a list

A

Arturo

Hello –
I have a list of numbers in A1:A10, 1 through 10.
From that list of numbers, what I’ve got below is partially working, but I
cannot seem to find how to generate a whole random # from that list…


Sub GenRand2()
Dim myRange As Range
Dim rO As Integer
Dim Result As Double

Set myRange = Worksheets("Sheet1") _
.Range("A1").CurrentRegion
rO = myRange.Rows.Count

Result = rO * Rnd()
MsgBox Result

End Sub


Sincerely,
Arturo
 
M

mooncrawler

Sub GenRand2()
Dim myRange As Range
Dim rO As Integer
Dim Result As Double
Set myRange = Worksheets("Sheet1") _
.Range("A1").CurrentRegion
rO = myRange.Rows.Count
Randomize
Result = Int((rO * Rnd) + 1)
MsgBox Result
End Sub
 
T

Tushar Mehta

Assuming (a) by whole random # you mean a number from the myRange
range, and (b) CurrentRegion consists of a single column, use

Result = myRange.Cells(Fix(rO * Rnd() + 1), 1)


--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

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