LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Random is not really random

i have a sub that chooses a random book of the bible (list of books is
on Sheet1) & inserts the name of the book in a textbox. after that
book has been chosen, the row gets hidden so it doesn't get chosen
again.

i open the spreadsheet & press the "select" button which runs the
sub. i get (after pressing the button 3x):
1. Acts
2. Philippians
3. Jonah

ok, fine. close the workbook without saving (so those rows don't get
hidden). open the workbook, and press the button 3x again. i get:
1. Acts
2. Philippians
3. Jonah.

so the response is technically random, but not really random. any
ideas? i can live with it the way it is, but i'm just curious as to
why i don't get different books the 2nd time i press the button 3x.
(at this point most of the books are visible.) the pertinent code
follows:
=========================
Private Sub cmdSelect_Click()
Dim ws1 As Worksheet
Dim rVis As Range
Dim iRnd As Long
Dim iRow As Long
Dim cell As Range
Dim RandomBook As String
Dim myBook As Range

Set ws1 = ActiveWorkbook.Worksheets("Sheet1")

'find a random bible book from column A
'from the visible cells only (ones not chosen
'previously)
Set rVis = ws1.Range("A1", ws1.Range("A1").End(xlDown)) _
.SpecialCells(xlCellTypeVisible)
iRnd = Int(rVis.Count * Rnd) + 1

For Each cell In rVis
iRow = iRow + 1
If iRow = iRnd Then Exit For
Next cell

iRow = cell.Row
Set myBook = ws1.Range("a" & iRow)

RandomBook = myBook.Value

'enter the bible book in the textbox
Me.txtBook.Value = RandomBook

myBook.EntireRow.Hidden = True

End Sub
==============================
thanks in advance for any insight.
:)
susan


 
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
Random phantom breakpoints and random bogus compile errors Greg Lovern Excel Programming 5 June 2nd 10 03:52 PM
Sorting random Data created from a random formula Six Sigma Blackbelt Excel Discussion (Misc queries) 1 September 11th 08 11:03 PM
Non-random numbers generated by excel's data analysis random gener Allie Excel Worksheet Functions 10 September 17th 05 06:19 AM
Non-random numbers generated by excel's data analysis random gener Harlan Grove Excel Discussion (Misc queries) 2 September 13th 05 04:06 PM
How do I find random number in list of random alpha? (Position is. jlahealth-partners Excel Discussion (Misc queries) 0 February 8th 05 05:31 PM


All times are GMT +1. The time now is 07:04 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"