Results 1 to 4 of 4

Thread: Random Unique Value Generator Based On Sample Size And Maximum Items Limit

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Question Random Unique Value Generator Based On Sample Size And Maximum Items Limit

    Hi All,

    Thanks for your precious time in supporting me, my need is that i have a set of reference number in my excel sheet and i have desired counts (sample size) that i need to randomly select from the set of reference numbers and allocate them to few persons in next sheet (that i will be input their name and how many reference numbers should be allocated to a particular person, the persons and their count will change daily)

    I uploaded my sample workbook, please download and help me in this regard.

    Pls come back if any of my explanation is not understandable.

    Once again thanks for your precious time.....friends...`



    i have already posted this thread in excel forum for reference pls see below

    Need to organize data based on requirements....explained below

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Attached Files Attached Files
    Last edited by DocAElstein; 10-02-2023 at 12:41 PM.

  2. #2
    Member
    Join Date
    Jun 2013
    Posts
    93
    Rep Power
    12
    put in K10 the formula
    Code:
    =COUNTIF($D$2:$D$61,J10)

  3. #3
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Paste this to the code module of the respective sheet and run the macro.

    Code:
    Sub RandLookUp()
    
        Dim lng As Long
        Dim lngMax As Long: lngMax = Range("L5").Value
        Dim lngMin As Long: lngMin = Range("K5").Value
        Dim strNames(1 To 5000) As String
        
        With CreateObject("Scripting.Dictionary")
            Do While .Count <= Range("K7").Value 'lngMax - lngMin          'removed the greater than symbol
                lng = Rnd * (lngMax - lngMin) + lngMin  'removed the +1
                .Item(lng) = Empty
            Loop
            lngMin = Empty
            For lng = 1 To Range("J10:J18").Rows.Count
                If Not IsEmpty(Range("J10:J18").Cells(lng, 1)) Then
                    For lngMax = 1 To Range("J10:J18").Cells(lng, 2).Value
                        lngMin = lngMin + 1
                        strNames(lngMin) = Range("J10:J18").Cells(lng, 1).Value
                    Next lngMax
                End If
            Next lng
            Range(Range("A2"), Cells(Rows.Count, 1).End(xlUp)).Resize(, 4).ClearContents
            Range("A2").Resize(Range("K7").Value).Value = Application.Transpose(.Keys)
            Range("B2").Resize(Range("K7").Value, 2).Formula = "=VLOOKUP($A2,Sheet1!$A:B,COLUMN(),0)"
            Range("D2").Resize(Range("K7").Value).Value = Application.Transpose(strNames)
        End With
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  4. #4
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0
    Thanks a lot Admin...

Similar Threads

  1. Replies: 10
    Last Post: 08-29-2013, 08:20 PM
  2. Replies: 14
    Last Post: 06-27-2013, 10:57 AM
  3. Unique Random Number In Ascending Order
    By marreco in forum Excel Help
    Replies: 8
    Last Post: 11-04-2012, 04:15 PM
  4. Random Unique Number Generator Excel VBA
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 5
    Last Post: 10-18-2012, 01:00 PM
  5. Create Random Number Generator VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 1
    Last Post: 12-01-2011, 10:51 AM

Posting Permissions

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