ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   generating a whole random # from a list (https://www.excelbanter.com/excel-programming/336967-generating-whole-random-list.html)

Arturo

generating a whole random # from a list
 
Hello €“
I have a list of numbers in A1:A10, 1 through 10.
From that list of numbers, what Ive 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

mooncrawler[_2_]

generating a whole random # from a 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
Randomize
Result = Int((rO * Rnd) + 1)
MsgBox Result
End Sub

"Arturo" schreef in bericht
...
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




Tushar Mehta

generating a whole random # from a list
 
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

In article ,
says...
Hello ¤=3F
I have a list of numbers in A1:A10, 1 through 10.
From that list of numbers, what I¤=3Fve got below is partially working, but I
cannot seem to find how to generate a whole random # from that list¤=3F


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



All times are GMT +1. The time now is 07:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com