Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating random numbers tobbey Excel Worksheet Functions 2 January 5th 10 08:05 AM
Generating Random numbers. Tyler Excel Discussion (Misc queries) 3 September 22nd 07 09:48 PM
generating random number list yvette Excel Worksheet Functions 1 January 12th 07 05:07 PM
Generating Random Number from a set of numbers CalsLib Excel Discussion (Misc queries) 3 March 17th 06 04:27 PM
generating random number as template Jemm Excel Discussion (Misc queries) 2 July 6th 05 01:47 PM


All times are GMT +1. The time now is 02:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"