+ Reply to Thread
Results 1 to 3 of 3

Random numbers generation

  1. #1
    Nishant
    Guest

    Random numbers generation

    Hello,
    I am new to VBA scripting, I have a problem that in an excel sheet i
    have got a large number of cusips in a column. I want to pull cusips
    randomly from that list. I am currently doing a RANDBETWEEN after
    calculating the number of rows and getting to the row no that comes in
    the random number.the problem is that everday the no of rows keep on
    changing. I want to write a macro for the same .
    Thanks in advance.
    Nishant


  2. #2
    Tom Ogilvy
    Guest

    Re: Random numbers generation

    Dim rng as Range, rng1 as Range, num as Long
    set rng = Range(cells(2,5),cells(2,5).End(xldown))
    num = int(rnd()*rng.count+1)
    set rng1 = rng(num)
    msgbox rng1.value

    --
    Regards,
    Tom Ogilvy

    "Nishant" <nishant.nayar@gmail.com> wrote in message
    news:1134044502.372713.254580@g44g2000cwa.googlegroups.com...
    > Hello,
    > I am new to VBA scripting, I have a problem that in an excel sheet i
    > have got a large number of cusips in a column. I want to pull cusips
    > randomly from that list. I am currently doing a RANDBETWEEN after
    > calculating the number of rows and getting to the row no that comes in
    > the random number.the problem is that everday the no of rows keep on
    > changing. I want to write a macro for the same .
    > Thanks in advance.
    > Nishant
    >




  3. #3
    Nishant Nayar
    Guest

    Re: Random numbers generation



    hi,
    I tried running the script but got the error message

    Sub Macro1()

    Macro1 Macro

    Dim rng as Range, rng1 as Range, num as Long
    set rng = Range(cells(2,5),cells(2,5).End(xldown))
    num = int(rnd()*rng.count+1)
    set rng1 = rng(num)
    msgbox rng1.value

    End Sub

    *** Sent via Developersdex http://www.developersdex.com ***

+ 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