+ Reply to Thread
Results 1 to 7 of 7

Lucky Draw VBA with multiple winners, multiple conditions

  1. #1
    Registered User
    Join Date
    09-21-2021
    Location
    Bucharest, Romania
    MS-Off Ver
    365
    Posts
    19

    Lucky Draw VBA with multiple winners, multiple conditions

    Hello Guys,

    So what I've been struggling with for a few days is trying to find / adapt / create a template of a lucky winner draw vba code that can:
    1. randomly draw a number of values (winners) from column A - without having duplicates
    2. for each of the drawn winners also check if the info associated to them in column B is also unique
    3. print winners and corresponding info from column B to spreadsheet

    I've managed to find a guy that wrote a code that does point 1 but I have no idea how to integrate the second match and validation into the entire thing. I've attached an example sheet with what I am looking to do.

    Looking forward to your expertise! Thanks

    Lucky Draw Multiple winners multiple conditions example.xlsm

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Lucky Draw VBA with multiple winners, multiple conditions

    Give this code a try:

    Please Login or Register  to view this content.
    Last edited by maniacb; 03-13-2023 at 12:30 PM.

  3. #3
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Lucky Draw VBA with multiple winners, multiple conditions

    Here is a more accurate solution.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,659

    Re: Lucky Draw VBA with multiple winners, multiple conditions

    Try
    Please Login or Register  to view this content.
    Last edited by jindon; 03-14-2023 at 02:39 AM. Reason: Add error check for infinite loop.

  5. #5
    Registered User
    Join Date
    09-21-2021
    Location
    Bucharest, Romania
    MS-Off Ver
    365
    Posts
    19

    Re: Lucky Draw VBA with multiple winners, multiple conditions

    Thank you for your suggestion but it's still not what I'm looking for. I need the script to also check for duplicate codes, for example:

    If Person1 sent Code003 but Person4 also sent Code003, if the script first picks Person1 as a winner it needs to not be able to then pick Person4 because that persons code would already have been picked before.


  6. #6
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,496

    Re: Lucky Draw VBA with multiple winners, multiple conditions

    Try:
    PHP Code: 
    Sub PickNamesAtRandom()
    Dim i&, rngrname As Stringcode As StringdicName As ObjectdicCode As Object
    Set dicName 
    CreateObject("Scripting.Dictionary")
    Set dicCode CreateObject("Scripting.Dictionary")
    rng Range("A2:B" Cells(Rows.Count"A").End(xlUp).Row).Value
    For 1 To UBound(rng)
        If 
    Not dicName.exists(rng(i1)) Then dicName.Add rng(i1), ""
        
    If Not dicCode.exists(rng(i2)) Then dicCode.Add rng(i2), ""
    Next
    Randomize
    For 1 To Range("D3").Value
        
    Do
            
    Int(Rnd UBound(rng)) + 1
            name 
    rng(r1): code rng(r2)
        
    Loop Until dicName.exists(name) And dicCode.exists(code)
        
    dicName.Remove (name): dicCode.Remove (code)
        
    Range("D5").Offset(i0).Value name
    Next
    End Sub 
    Quang PT

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,659

    Re: Lucky Draw VBA with multiple winners, multiple conditions

    Quote Originally Posted by alekoo View Post
    ??
    You are confusing us.

    Code in post #4 is tested before I post and no duplicates in both columns.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Lucky draw - randomly select lucky winners
    By booneleong in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-22-2020, 06:33 PM
  2. Picking out multiple winners
    By Tresfjording in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-02-2018, 08:39 AM
  3. Replies: 1
    Last Post: 07-20-2018, 11:14 PM
  4. [SOLVED] Lucky Draw with probability distribution
    By lkdwong in forum Excel General
    Replies: 2
    Last Post: 02-21-2017, 01:36 AM
  5. VBA for Lucky draw displaying numbers
    By Jan Van der Borght in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-30-2015, 10:27 AM
  6. Random name generator with no duplicates for company's lucky draw segment
    By nekolaypeng in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-09-2014, 05:39 AM
  7. Create Lucky Draw game in Excel or PowerPoint
    By alibaba in forum Excel General
    Replies: 1
    Last Post: 10-23-2009, 01:16 AM

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