+ Reply to Thread
Results 1 to 3 of 3

generating a whole random # from a list

  1. #1
    Arturo
    Guest

    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 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

  2. #2
    mooncrawler
    Guest

    Re: 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" <[email protected]> schreef in bericht
    news:[email protected]...
    > 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. #3
    Tushar Mehta
    Guest

    Re: generating a whole random # from a list

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

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


    --=20
    Regards,

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

    In article <[email protected]>,=20
    [email protected] says...
    > Hello =E2=A4=3D3F
    > I have a list of numbers in A1:A10, 1 through 10.
    > From that list of numbers, what I=E2=A4=3D3Fve got below is partially wor=

    king, but I=20
    > cannot seem to find how to generate a whole random # from that list=E2=A4=

    =3D3F
    >=20
    >=20
    > Sub GenRand2()
    > Dim myRange As Range
    > Dim rO As Integer
    > Dim Result As Double
    >=20
    > Set myRange =3D Worksheets("Sheet1") _
    > .Range("A1").CurrentRegion
    > rO =3D myRange.Rows.Count
    > =20
    > Result =3D rO * Rnd()
    > MsgBox Result
    >=20
    > End Sub
    >=20
    >=20
    > Sincerely,
    > Arturo
    >=20


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1