+ Reply to Thread
Results 1 to 5 of 5

Random Row Select and Copy

  1. #1
    Registered User
    Join Date
    02-12-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    4

    Random Row Select and Copy

    help.jpgHi Guys,
    I am creating a report were I can generate 5 or more Random entries in another sheet.
    One Row is one entry.
    If I have 500 entries, how can I randomly pick 5 (or more depending on the user's choice) from these 500 entries and copy them automatically to the next sheet.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Random Row Select and Copy

    Hi,

    Try this:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    02-12-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Random Row Select and Copy

    Thanks xladept.... But how will I use it? Im just a plain excel user. ;p

    Sub xtiank(): Dim i As Long, j As Long, n As Long, R() As Long
    Dim ws As Worksheet: Set ws = ActiveWorkbook.Sheets("Next Sheet")
    n = Val(InputBox("How many numbers???"))
    ReDim R(n + 1)
    For i = 1 To n
    DeDupe:
    R(i) = Int(Rnd() * 500) + 1
    For j = 1 To i
    If j = i Then Exit For
    If R(i) = R(j) Then GoTo DeDupe
    Next j: Next i

    Let j = ws.Range("A" & Rows.Count).End(xlUp).Row

    For i = 1 To n
    Rows(R(i)).Copy ws.Range("A" & j): j = j + 1
    Next i

    End Sub

  4. #4
    Registered User
    Join Date
    02-12-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Random Row Select and Copy

    Hi xladept, I was able to run the code using a button named Random.
    Thank you very much.
    How will I erase the previous random list after I press the Random Button?
    And make another random list?
    I once used Visual Basic before, and it was 13 years ago and I forgot everything.
    cheers!

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Random Row Select and Copy

    Wherever it is just clear contents

    Please Login or Register  to view this content.
    Last edited by xladept; 02-20-2013 at 11:27 PM.

+ 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