+ Reply to Thread
Results 1 to 2 of 2

Getting a Random list of names

  1. #1
    Registered User
    Join Date
    04-13-2005
    Posts
    1

    Getting a Random list of names

    Hello!!
    I have around 1200 names and I need to select a random list of 200 names. I tried to create a Macro using the following formula and it gives me an error message. I would appreciate any help. Or if there is an easier formula, I could use that as well.

    Thank you in advance for your time.
    VB

    Sub GetRandom()
    Dim iRows As Integer
    Dim iCols As Integer
    Dim iBegRow As Integer
    Dim iBegCol As Integer
    Dim J As Integer
    Dim sCells As String

    Set TempDO = New DataObject


    iRows = Selection.Rows.Count
    iCols = Selection.Columns.Count
    iBegRow = Selection.Row
    iBegCol = Selection.Column

    If iRows < 1201 Or iCols > 1 Then
    MsgBox "Too few rows or too many columns"
    Else
    Randomize Timer
    sCells = ""
    For J = 1 To 200
    iWantRow = Int(Rnd() * iRows) + iBegRow
    sCells = sCells & Cells(iWantRow, iBegCol) & vbCrLf
    Next J
    TempDO.SetText sCells
    TempDO.PutInClipboard
    End If
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Vijaybidappa,

    You didn't mention which line in the code was causing an error. I would guess the Set TempDO = New DataObject.

    You first must delcare TempDO with a Dim statement with the type DataObject. You can't assign a variable to a non existant object. As far as shortening your code, you really can't do much more with it than what you have done so far.

    Hope this helps,
    Leith Ross

+ 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