+ Reply to Thread
Results 1 to 4 of 4

random non-repeating names

  1. #1
    Registered User
    Join Date
    02-16-2005
    Posts
    3

    random non-repeating names

    I have a sheet of names (all ID'd 1-700), and I would like to randomly pull 35 names from the list with out any repeats. Where should I begin.

  2. #2
    p.hall
    Guest

    Re: random non-repeating names

    Assuming your IDs are in col A and the names are in col B, this sub
    will pick 35 unique names and put them in col C.

    Sub GetNames()
    Dim x As Integer
    Dim intNum As Integer
    Dim arrNames(34) As String, strName As String
    Dim blnNameFound As Boolean

    x = 0
    Do Until x = 35

    blnNameFound = False
    Randomize (Timer)

    '--Randomly pick the ID
    intNum = Rnd(1) * 700 + 1

    '--Get the corresponding name
    strName = Cells(intNum, 2)

    '--Check the array for that name and set a boolean to true if found
    For y = 0 To 34
    If strName = arrNames(y) Then
    blnNameFound = True
    Exit For
    End If
    Next y

    '--If the name was not found, add it to the array
    If blnNameFound = False Then
    arrNames(x) = strName
    x = x + 1
    End If

    Loop

    Does this help?


    'Put the 35 names in column C
    For x = 0 To 34
    Cells(x + 1, 3) = arrNames(x)
    Next

    End Sub


  3. #3
    Registered User
    Join Date
    02-16-2005
    Posts
    3
    that is it... perfect... thanks for the help

  4. #4
    Tushar Mehta
    Guest

    Re: random non-repeating names

    Random Selection
    http://www.tushar-mehta.com/excel/ne...ion/index.html

    --
    Regards,

    Tushar Mehta
    www.tushar-mehta.com
    Multi-disciplinary business expertise
    + Technology skills
    = Optimal solution to your business problem
    Recipient Microsoft MVP award 2000-2005

    In article <[email protected]>, rivet.1kkd04
    @excelforum-nospam.com says...
    >
    > I have a sheet of names (all ID'd 1-700), and I would like to randomly
    > pull 35 names from the list with out any repeats. Where should I begin.
    >
    >
    > --
    > rivet
    > ------------------------------------------------------------------------
    > rivet's Profile: http://www.excelforum.com/member.php...o&userid=20022
    > View this thread: http://www.excelforum.com/showthread...hreadid=346087
    >
    >


+ 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