Lucky draw

Kitri

New Member
Joined
Dec 7, 2021
Messages
10
Office Version
  1. 2010
Platform
  1. Windows
Hi there,
I was assigned a task about lucky draw with conditions and arrangement as follow :
1. There will be 100 employees and 5 prizes
2. Prize will be split into 5 categories :
a. 1st draw : 50 employees with nominal prize ($100/each)
b. 2nd draw : 25 employees with nominal prize ($200/each)
c. 3rd draw : 15 employees with nominal prize ($300/each)
d. 4th draw : 8 employees with nominal prize ($400/each)
e. 5th draw : 2 employees with nominal prize ($500/each)

Need your kind advise on this task since I’m quite new on learning vba.

Thank you in advance :)
 
Aha! So let me try Rephrase V2.

1) You have 100 employees.
2) You want to generate a random list of 50 of those employee names. They will all receive $100.
3) You then want to generate a random list of 25 employees of the 50 remaining employees. They will all receive $200.
4) You then want to generate a random list of 15 employees of the 25 remaining employees. They will all receive $300.
5) You then want to generate a random list of 8 employees of the 10 remaining employees. They will all receive $400.
6) Last drawing is pointless because there are only 2 employees left that will receive $500 each.

That all correct?
Yes..correct..
Sorry for unclear information.

Need your advise on it :)
Thankyou very much
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Aha! So let me try Rephrase V2.

1) You have 100 employees.
2) You want to generate a random list of 50 of those employee names. They will all receive $100.
3) You then want to generate a random list of 25 employees of the 50 remaining employees. They will all receive $200.
4) You then want to generate a random list of 15 employees of the 25 remaining employees. They will all receive $300.
5) You then want to generate a random list of 8 employees of the 10 remaining employees. They will all receive $400.
6) Last drawing is pointless because there are only 2 employees left that will receive $500 each.

That all correct?

One more question. Where is your list of employee names? What sheet name and what address range?
Lucky Draw v4.xlsm
ABCDEFGHIJK
1NoNamePrizeFaakhira
21Aatifa$ 500Naditya
32Abida$ 400Luisa
43Beatarisa$ 300Daniza
54Caera$ 200Kaila
65Daniza$ 100Erina
76ElainaCalandra
87FadhilaBaahirah
98CassiaQanshana
109AbilaElvaretta
1110AlsavaAazkiya
1211DavidyaKanaya
1312FaihaDavidya
1413BaahirahKalya
1514AbiaLanakila
1615DanitaLuna
1716DesiBadriyyah
1817ElvarettaCassia
1918AbabilErmina
2019BadriyyahElaina
2120DentaAbia
2221CalyaCassaundra
2322BarshaQuerida
2423EishaFaiha
2524FahimahCarabella
2625FaakhiraDesi
2726DavinaBeatarisa
2827CarabellaFairuz
2928DarriaDanita
3029BahzyQaila
3130AathifaBasmah
3231CassaundraBayuni
3332CadenzaDavina
3433CeisyaKalila
3534BasmahChalinda
3635DaryanAlexzandra
3736ChalindaOceana
3837AdiraAbdilla
3938EdreaEdrea
4039BerilLesya
4140BayuniCaera
4241DanizaKania
4342DesiNamira
4443BadriyyahCasia
4544DanitaNadira
4645FaihahQiandra
4746FairuzCeisya
4847BeatarisaDarria
4948EshalDenta
5049Erina
5150Calandra
5251Davidya
5352Casia
5453Abia
5554Faiha
5655Alexzandra
5756Denta
5857Ababil
5958Ermina
6059Aazkiya
6160Abdilla
6261Faiha
6362Faihah
6463Kaila
6564Kalila
6665Kalya
6766Kamala
6867Kamaniai
6968Kanaya
7069Kania
7170Kanisha
7271Kanti
7372Kanzia
7473Laila
7574Lanakila
7675Lavina
7776Lesya
7877Luisa
7978Luna
8079Naava
8180Nadira
8281Naditya
8382Nafiza
8483Naifa
8584Nailazaara
8685Namira
8786Nandita
8887Nara
8988Naraya
9089Oceana
9190Oksana
9291Omkara
9392Opaline
9493Ophelia
9594Oriana
9695Qaila
9796Qaissara
9897Qanshana
9998Qeiza
10099Qiandra
101100Querida
Data
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:B41Cell ValueduplicatestextNO
B2:B21Cell ValueduplicatestextNO
A2:A101Cell ValueduplicatestextNO
A2:A101Cell ValueduplicatestextNO
G1:G33,G94:G1048576Cell ValueduplicatestextNO
G1:G13,G94:G1048576Cell ValueduplicatestextNO
F:FCell ValueduplicatestextNO
 
Upvote 0
I took your original sheet, and added a RAND() formula in column C, and I added some Conditional Formatting to show the prize ranges:

Book1
ABCDEF
1NoNamePrizeCountcumulative count
21Aatifa0.34298171100500
32Abida0.540979992002550
43Beatarisa0.227245883001575
54Caera0.9252929400890
65Daniza0.90906489500298
76Elaina0.69760485
87Fadhila0.41560432
98Cassia0.00096727
109Abila0.84453264
1110Alsava0.29367193
1211Davidya0.2817714
1312Faiha0.57428575
1413Baahirah0.8134641
1514Abia0.5835496
1615Danita0.95712484
1716Desi0.54401229
1817Elvaretta0.85008631
1918Ababil0.56265351
2019Badriyyah0.62274343
2120Denta0.92668269
2221Calya0.92624384
2322Barsha0.23817511
2423Eisha0.34507431
2524Fahimah0.37351632
2625Faakhira0.68939205
2726Davina0.29212251
2827Carabella0.82123661
2928Darria0.63145938
3029Bahzy0.11834371
3130Aathifa0.13322738
3231Cassaundra0.64894095
3332Cadenza0.40876986
3433Ceisya0.85777725
3534Basmah0.89335751
3635Daryan0.46910052
3736Chalinda0.96967176
3837Adira0.4908153
3938Edrea0.5982872
4039Beril0.52343243
4140Bayuni0.35717182
4241Daniza0.26052914
4342Desi0.40836032
4443Badriyyah0.78798695
4544Danita0.36046969
4645Faihah0.61727093
4746Fairuz0.31567974
4847Beatarisa0.41612788
4948Eshal0.28420766
5049Erina0.05504288
5150Calandra0.8082805
5251Davidya0.74922074
5352Casia0.83507641
5453Abia0.45562655
5554Faiha0.04486417
5655Alexzandra0.84453445
5756Denta0.85305012
5857Ababil0.66637342
5958Ermina0.70814812
6059Aazkiya0.12043527
6160Abdilla0.39724514
6261Faiha0.61708386
6362Faihah0.91118791
6463Kaila0.3035328
6564Kalila0.93519161
6665Kalya0.49681569
6766Kamala0.90402001
6867Kamaniai0.26190232
6968Kanaya0.30384547
7069Kania0.22520539
7170Kanisha0.82071755
7271Kanti0.98926113
7372Kanzia0.27276425
7473Laila0.79415256
7574Lanakila0.40354201
7675Lavina0.46230847
7776Lesya0.1004042
7877Luisa0.28978664
7978Luna0.17665188
8079Naava0.09784831
8180Nadira0.44786347
8281Naditya0.82013238
8382Nafiza0.45722878
8483Naifa0.99822482
8584Nailazaara0.97544601
8685Namira0.36988327
8786Nandita0.28768657
8887Nara0.30462204
8988Naraya0.13447245
9089Oceana0.81782011
9190Oksana0.27120957
9291Omkara0.44610259
9392Opaline0.59400942
9493Ophelia0.15023607
9594Oriana0.25260356
9695Qaila0.11797867
9796Qaissara0.50075873
9897Qanshana0.66158651
9998Qeiza0.00619509
10099Qiandra0.71265379
101100Querida0.22639586
102
Sheet1
Cell Formulas
RangeFormula
C2:C101C2=RAND()
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B:BExpression=MATCH(ROW()-2,$F$2:$F$6)=5textNO
B:BExpression=MATCH(ROW()-2,$F$2:$F$6)=4textNO
B:BExpression=MATCH(ROW()-2,$F$2:$F$6)=3textNO
B:BExpression=MATCH(ROW()-2,$F$2:$F$6)=2textNO
B:BExpression=MATCH(ROW()-2,$F$2:$F$6)=1textNO


Once you have it set up like this, just select columns B:C, click Sort & Filter > Custom Sort > Sort by > Column C. It will sort the names randomly, and color code each group.
 
Upvote 0
Ok, here is what I whipped up for a VBA code solution:

Example results:

PSpenceV1.xlsm
ABCDEFGHIJKLMNOPQRST
1NoNamePrize# of $100 Prize WinnersEmployee Name# of $200 Prize WinnersEmployee Name# of $300 Prize WinnersEmployee Name# of $400 Prize WinnersEmployee Name# of $500 Prize WinnersEmployee Name
21Aatifa5001Querida1Namira1Abdilla1Elaina1Calya
32Abida4002Cassia2Beatarisa2Kamaniai2Erina2Faiha
43Beatarisa3003Aatifa3Oksana3Faakhira3Casia
54Caera2004Chalinda4Alsava4Davidya4Abida
65Daniza1005Bayuni5Nailazaara5Omkara5Lavina
76Elaina6Alexzandra6Nara6Beril6Kaila
87Fadhila7Kalila7Basmah7Kanaya7Kanisha
98Cassia8Eshal8Caera8Opaline8Adira
109Abila9Qeiza9Aazkiya9Denta
1110Alsava10Desi10Abia10Daryan
1211Davidya11Aathifa11Naava11Kanti
1312Faiha12Qaila12Qanshana12Daniza
1413Baahirah13Beatarisa13Edrea13Davina
1514Abia14Luna14Lanakila14Elvaretta
1615Danita15Laila15Nadira15Ophelia
1716Desi16Kamala16Ababil
1817Elvaretta17Cassaundra17Danita
1918Ababil18Fairuz18Desi
2019Badriyyah19Ceisya19Nafiza
2120Denta20Badriyyah20Qiandra
2221Calya21Eisha21Naditya
2322Barsha22Daniza22Oceana
2423Eisha23Badriyyah23Cadenza
2524Fahimah24Abila24Kalya
2625Faakhira25Faihah25Lesya
2726Davina26Davidya
2827Carabella27Barsha
2928Darria28Baahirah
3029Bahzy29Bahzy
3130Aathifa30Qaissara
3231Cassaundra31Nandita
3332Cadenza32Faiha
3433Ceisya33Denta
3534Basmah34Abia
3635Daryan35Carabella
3736Chalinda36Naifa
3837Adira37Faihah
3938Edrea38Luisa
4039Beril39Ermina
4140Bayuni40Darria
4241Daniza41Kania
4342Desi42Naraya
4443Badriyyah43Calandra
4544Danita44Fadhila
4645Faihah45Oriana
4746Fairuz46Danita
4847Beatarisa47Faiha
4948Eshal48Fahimah
5049Erina49Ababil
5150Calandra50Kanzia
5251Davidya
5352Casia
5453Abia
5554Faiha
5655Alexzandra
5756Denta
5857Ababil
5958Ermina
6059Aazkiya
6160Abdilla
6261Faiha
6362Faihah
6463Kaila
6564Kalila
6665Kalya
6766Kamala
6867Kamaniai
6968Kanaya
7069Kania
7170Kanisha
7271Kanti
7372Kanzia
7473Laila
7574Lanakila
7675Lavina
7776Lesya
7877Luisa
7978Luna
8079Naava
8180Nadira
8281Naditya
8382Nafiza
8483Naifa
8584Nailazaara
8685Namira
8786Nandita
8887Nara
8988Naraya
9089Oceana
9190Oksana
9291Omkara
9392Opaline
9493Ophelia
9594Oriana
9695Qaila
9796Qaissara
9897Qanshana
9998Qeiza
10099Qiandra
101100Querida
102
Sheet4



VBA macro code to be placed into a separate module and then ran:

VBA Code:
Sub Name_Prize_GeneratorV1()
'
    Dim LastRow                             As Long
    Dim RandomEmployeeNumberPicked          As Long, RandomEmployeeNumberPickedCounter  As Long, RandomNumberGeneratedCounter   As Long
    Dim RandomEmployeeNumberPickedArray     As Object
    Dim EmployeeArray                       As Variant
    Dim wsSource                            As Worksheet
'
    Set wsSource = Sheets("Sheet4")                                                     ' <--- Set this to the sheet name that contains the employee list
'
    LastRow = wsSource.Range("B" & Rows.Count).End(xlUp).Row                            ' Get Last Row Number of employee names
'
    EmployeeArray = wsSource.Range("B2:B" & LastRow)                                    ' Load Employee names into a 2D 1 based array RC
'
    Set RandomEmployeeNumberPickedArray = CreateObject("Scripting.Dictionary")          ' Establish Dictionary Array
'
    RandomEmployeeNumberPickedCounter = 1                                               ' Initialize RandomEmployeeNumberPickedCounter
'
'
'   '-----------------------------'
'   ' Generate the random numbers '
'   '-----------------------------'
'
    While RandomEmployeeNumberPickedArray.Count < 100                                   ' Establish loop to generate 100 unique random numbers ... 1 to 100
        RandomEmployeeNumberPicked = Application.WorksheetFunction.RandBetween(1, 100)  '   Generate random number between 1 & 100
'
        If Not RandomEmployeeNumberPickedArray.Exists(RandomEmployeeNumberPicked) Then  '   If this is a unique random # then ...
            RandomEmployeeNumberPickedArray.Add RandomEmployeeNumberPicked, RandomEmployeeNumberPickedCounter   '       Save the number into dictionary array
            RandomEmployeeNumberPickedCounter = RandomEmployeeNumberPickedCounter + 1   '       Increment the RandomEmployeeNumberPickedCounter
        End If
    Wend                                                                                ' Loop back
'
'
'   '-----------------------------'
'   ' Display Drawing # 1 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 50                                          ' Establish loop to loop through first 50 #s randomly generated
        wsSource.Range("F" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 50
'
'       Display associated names to those random #s generated
        wsSource.Range("G" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter - 1), 1)
    Next                                                                                ' Loop Back
'
'
'   '-----------------------------'
'   ' Display Drawing # 2 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 25                                          ' Establish loop to loop through next 25 #s randomly generated
        wsSource.Range("I" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 25
'
'       Display associated names to those random #s generated
        wsSource.Range("j" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 49), 1)
    Next                                                                                ' Loop Back
'
'
'   '-----------------------------'
'   ' Display Drawing # 3 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 15                                          ' Establish loop to loop through next 15 #s randomly generated
        wsSource.Range("L" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 15
'
'       Display associated names to those random #s generated
        wsSource.Range("M" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 74), 1)
    Next                                                                                ' Loop Back
'
'
'   '-----------------------------'
'   ' Display Drawing # 4 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 8                                           ' Establish loop to loop through next 8 #s randomly generated
        wsSource.Range("O" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 8
'
'       Display associated names to those random #s generated
        wsSource.Range("P" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 89), 1)
    Next                                                                                ' Loop Back
'
'
'   '-----------------------------'
'   ' Display Drawing # 5 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 2                                           ' Establish loop to loop through last 2 #s randomly generated
        wsSource.Range("R" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 2
'
'       Display associated names to those random #s generated
        wsSource.Range("S" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 97), 1)
    Next                                                                                ' Loop Back
End Sub
 
Upvote 0
Sub Name_Prize_GeneratorV1() ' Dim LastRow As Long Dim RandomEmployeeNumberPicked As Long, RandomEmployeeNumberPickedCounter As Long, RandomNumberGeneratedCounter As Long Dim RandomEmployeeNumberPickedArray As Object Dim EmployeeArray As Variant Dim wsSource As Worksheet ' Set wsSource = Sheets("Sheet4") ' <--- Set this to the sheet name that contains the employee list ' LastRow = wsSource.Range("B" & Rows.Count).End(xlUp).Row ' Get Last Row Number of employee names ' EmployeeArray = wsSource.Range("B2:B" & LastRow) ' Load Employee names into a 2D 1 based array RC ' Set RandomEmployeeNumberPickedArray = CreateObject("Scripting.Dictionary") ' Establish Dictionary Array ' RandomEmployeeNumberPickedCounter = 1 ' Initialize RandomEmployeeNumberPickedCounter ' ' ' '-----------------------------' ' ' Generate the random numbers ' ' '-----------------------------' ' While RandomEmployeeNumberPickedArray.Count < 100 ' Establish loop to generate 100 unique random numbers ... 1 to 100 RandomEmployeeNumberPicked = Application.WorksheetFunction.RandBetween(1, 100) ' Generate random number between 1 & 100 ' If Not RandomEmployeeNumberPickedArray.Exists(RandomEmployeeNumberPicked) Then ' If this is a unique random # then ... RandomEmployeeNumberPickedArray.Add RandomEmployeeNumberPicked, RandomEmployeeNumberPickedCounter ' Save the number into dictionary array RandomEmployeeNumberPickedCounter = RandomEmployeeNumberPickedCounter + 1 ' Increment the RandomEmployeeNumberPickedCounter End If Wend ' Loop back ' ' ' '-----------------------------' ' ' Display Drawing # 1 Results ' ' '-----------------------------' ' For RandomNumberGeneratedCounter = 1 To 50 ' Establish loop to loop through first 50 #s randomly generated wsSource.Range("F" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter ' Display counter of 1 - 50 ' ' Display associated names to those random #s generated wsSource.Range("G" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter - 1), 1) Next ' Loop Back ' ' ' '-----------------------------' ' ' Display Drawing # 2 Results ' ' '-----------------------------' ' For RandomNumberGeneratedCounter = 1 To 25 ' Establish loop to loop through next 25 #s randomly generated wsSource.Range("I" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter ' Display counter of 1 - 25 ' ' Display associated names to those random #s generated wsSource.Range("j" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 49), 1) Next ' Loop Back ' ' ' '-----------------------------' ' ' Display Drawing # 3 Results ' ' '-----------------------------' ' For RandomNumberGeneratedCounter = 1 To 15 ' Establish loop to loop through next 15 #s randomly generated wsSource.Range("L" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter ' Display counter of 1 - 15 ' ' Display associated names to those random #s generated wsSource.Range("M" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 74), 1) Next ' Loop Back ' ' ' '-----------------------------' ' ' Display Drawing # 4 Results ' ' '-----------------------------' ' For RandomNumberGeneratedCounter = 1 To 8 ' Establish loop to loop through next 8 #s randomly generated wsSource.Range("O" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter ' Display counter of 1 - 8 ' ' Display associated names to those random #s generated wsSource.Range("P" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 89), 1) Next ' Loop Back ' ' ' '-----------------------------' ' ' Display Drawing # 5 Results ' ' '-----------------------------' ' For RandomNumberGeneratedCounter = 1 To 2 ' Establish loop to loop through last 2 #s randomly generated wsSource.Range("R" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter ' Display counter of 1 - 2 ' ' Display associated names to those random #s generated wsSource.Range("S" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 97), 1) Next ' Loop Back End Sub
Hi,

thank you for the macro. it works but i found a duplicate name.

Lucky Draw v4.xlsm
ABCDEFGHIJKLMNOPQRST
1NoNamePrize$100$200$300$400$500
21Aatifa$ 5001Kanisha1Ermina1Cassia1Naifa1Lesya
32Abida$ 4002Qeiza2Fadhila2Daryan2Nadira2Luisa
43Beatarisa$ 3003Abia3Calya3Querida3Fahimah
54Caera$ 2004Naditya4Desi4Bahzy4Lavina
65Daniza$ 1005Chalinda5Kania5Kanaya5Kalya
76Elaina6Qiandra6Davidya6Kanzia6Ababil
87Fadhila7Naava7Aatifa7Kaila7Faiha
98Cassia8Alexzandra8Eshal8Elaina8Faiha
109Abila9Luna9Kalila9Faiha
1110Alsava10Nafiza10Faakhira10Daniza
1211Davidya11Fairuz11Ceisya11Nandita
1312Faiha12Nara12Casia12Kamala
1413Baahirah13Ababil13Beatarisa13Abia
1514Abia14Faihah14Carabella14Namira
1615Danita15Qaissara15Alsava15Denta
1716Desi16Beril16Nailazaara
1817Elvaretta17Darria17Abila
1918Ababil18Qanshana18Caera
2019Badriyyah19Omkara19Desi
2120Denta20Kamaniai20Oksana
2221Calya21Cassaundra21Kanti
2322Barsha22Calandra22Abida
2423Eisha23Basmah23Davina
2524Fahimah24Opaline24Beatarisa
2625Faakhira25Badriyyah25Cadenza
2726Davina26Qaila
2827Carabella27Aazkiya
2928Darria28Danita
3029Bahzy29Abdilla
3130Aathifa30Eisha
3231Cassaundra31Adira
3332Cadenza32Aathifa
3433Ceisya33Denta
3534Basmah34Bayuni
3635Daryan35Naraya
3736Chalinda36Baahirah
3837Adira37Oriana
3938Edrea38Barsha
4039Beril39Badriyyah
4140Bayuni40Elvaretta
4241Daniza41Daniza
4342Desi42Erina
4443Badriyyah43Faihah
4544Danita44Ophelia
4645Faihah45Danita
4746Fairuz46Edrea
4847Beatarisa47Lanakila
4948Eshal48Davidya
5049Erina49Oceana
5150Calandra50Laila
5251Davidya
5352Casia
5453Abia
5554Faiha
5655Alexzandra
5756Denta
5857Ababil
5958Ermina
6059Aazkiya
6160Abdilla
6261Faiha
6362Faihah
6463Kaila
6564Kalila
6665Kalya
6766Kamala
6867Kamaniai
6968Kanaya
7069Kania
7170Kanisha
7271Kanti
7372Kanzia
7473Laila
7574Lanakila
7675Lavina
7776Lesya
7877Luisa
7978Luna
8079Naava
8180Nadira
8281Naditya
8382Nafiza
8483Naifa
8584Nailazaara
8685Namira
8786Nandita
8887Nara
8988Naraya
9089Oceana
9190Oksana
9291Omkara
9392Opaline
9493Ophelia
9594Oriana
9695Qaila
9796Qaissara
9897Qanshana
9998Qeiza
10099Qiandra
101100Querida
Data
Cells with Conditional Formatting
CellConditionCell FormatStop If True
P2:P1048576Cell ValueduplicatestextNO
M2:M1048576Cell ValueduplicatestextNO
J2:J1048576Cell ValueduplicatestextNO
G2:G1048576Cell ValueduplicatestextNO
B2:B41Cell ValueduplicatestextNO
B2:B21Cell ValueduplicatestextNO
A2:A101Cell ValueduplicatestextNO
A2:A101Cell ValueduplicatestextNO
G2:G33,G94:G1048576Cell ValueduplicatestextNO
G2:G13,G94:G1048576Cell ValueduplicatestextNO

Ok, here is what I whipped up for a VBA code solution:

Example results:

PSpenceV1.xlsm
ABCDEFGHIJKLMNOPQRST
1NoNamePrize# of $100 Prize WinnersEmployee Name# of $200 Prize WinnersEmployee Name# of $300 Prize WinnersEmployee Name# of $400 Prize WinnersEmployee Name# of $500 Prize WinnersEmployee Name
21Aatifa5001Querida1Namira1Abdilla1Elaina1Calya
32Abida4002Cassia2Beatarisa2Kamaniai2Erina2Faiha
43Beatarisa3003Aatifa3Oksana3Faakhira3Casia
54Caera2004Chalinda4Alsava4Davidya4Abida
65Daniza1005Bayuni5Nailazaara5Omkara5Lavina
76Elaina6Alexzandra6Nara6Beril6Kaila
87Fadhila7Kalila7Basmah7Kanaya7Kanisha
98Cassia8Eshal8Caera8Opaline8Adira
109Abila9Qeiza9Aazkiya9Denta
1110Alsava10Desi10Abia10Daryan
1211Davidya11Aathifa11Naava11Kanti
1312Faiha12Qaila12Qanshana12Daniza
1413Baahirah13Beatarisa13Edrea13Davina
1514Abia14Luna14Lanakila14Elvaretta
1615Danita15Laila15Nadira15Ophelia
1716Desi16Kamala16Ababil
1817Elvaretta17Cassaundra17Danita
1918Ababil18Fairuz18Desi
2019Badriyyah19Ceisya19Nafiza
2120Denta20Badriyyah20Qiandra
2221Calya21Eisha21Naditya
2322Barsha22Daniza22Oceana
2423Eisha23Badriyyah23Cadenza
2524Fahimah24Abila24Kalya
2625Faakhira25Faihah25Lesya
2726Davina26Davidya
2827Carabella27Barsha
2928Darria28Baahirah
3029Bahzy29Bahzy
3130Aathifa30Qaissara
3231Cassaundra31Nandita
3332Cadenza32Faiha
3433Ceisya33Denta
3534Basmah34Abia
3635Daryan35Carabella
3736Chalinda36Naifa
3837Adira37Faihah
3938Edrea38Luisa
4039Beril39Ermina
4140Bayuni40Darria
4241Daniza41Kania
4342Desi42Naraya
4443Badriyyah43Calandra
4544Danita44Fadhila
4645Faihah45Oriana
4746Fairuz46Danita
4847Beatarisa47Faiha
4948Eshal48Fahimah
5049Erina49Ababil
5150Calandra50Kanzia
5251Davidya
5352Casia
5453Abia
5554Faiha
5655Alexzandra
5756Denta
5857Ababil
5958Ermina
6059Aazkiya
6160Abdilla
6261Faiha
6362Faihah
6463Kaila
6564Kalila
6665Kalya
6766Kamala
6867Kamaniai
6968Kanaya
7069Kania
7170Kanisha
7271Kanti
7372Kanzia
7473Laila
7574Lanakila
7675Lavina
7776Lesya
7877Luisa
7978Luna
8079Naava
8180Nadira
8281Naditya
8382Nafiza
8483Naifa
8584Nailazaara
8685Namira
8786Nandita
8887Nara
8988Naraya
9089Oceana
9190Oksana
9291Omkara
9392Opaline
9493Ophelia
9594Oriana
9695Qaila
9796Qaissara
9897Qanshana
9998Qeiza
10099Qiandra
101100Querida
102
Sheet4



VBA macro code to be placed into a separate module and then ran:

VBA Code:
Sub Name_Prize_GeneratorV1()
'
    Dim LastRow                             As Long
    Dim RandomEmployeeNumberPicked          As Long, RandomEmployeeNumberPickedCounter  As Long, RandomNumberGeneratedCounter   As Long
    Dim RandomEmployeeNumberPickedArray     As Object
    Dim EmployeeArray                       As Variant
    Dim wsSource                            As Worksheet
'
    Set wsSource = Sheets("Sheet4")                                                     ' <--- Set this to the sheet name that contains the employee list
'
    LastRow = wsSource.Range("B" & Rows.Count).End(xlUp).Row                            ' Get Last Row Number of employee names
'
    EmployeeArray = wsSource.Range("B2:B" & LastRow)                                    ' Load Employee names into a 2D 1 based array RC
'
    Set RandomEmployeeNumberPickedArray = CreateObject("Scripting.Dictionary")          ' Establish Dictionary Array
'
    RandomEmployeeNumberPickedCounter = 1                                               ' Initialize RandomEmployeeNumberPickedCounter
'
'
'   '-----------------------------'
'   ' Generate the random numbers '
'   '-----------------------------'
'
    While RandomEmployeeNumberPickedArray.Count < 100                                   ' Establish loop to generate 100 unique random numbers ... 1 to 100
        RandomEmployeeNumberPicked = Application.WorksheetFunction.RandBetween(1, 100)  '   Generate random number between 1 & 100
'
        If Not RandomEmployeeNumberPickedArray.Exists(RandomEmployeeNumberPicked) Then  '   If this is a unique random # then ...
            RandomEmployeeNumberPickedArray.Add RandomEmployeeNumberPicked, RandomEmployeeNumberPickedCounter   '       Save the number into dictionary array
            RandomEmployeeNumberPickedCounter = RandomEmployeeNumberPickedCounter + 1   '       Increment the RandomEmployeeNumberPickedCounter
        End If
    Wend                                                                                ' Loop back
'
'
'   '-----------------------------'
'   ' Display Drawing # 1 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 50                                          ' Establish loop to loop through first 50 #s randomly generated
        wsSource.Range("F" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 50
'
'       Display associated names to those random #s generated
        wsSource.Range("G" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter - 1), 1)
    Next                                                                                ' Loop Back
'
'
'   '-----------------------------'
'   ' Display Drawing # 2 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 25                                          ' Establish loop to loop through next 25 #s randomly generated
        wsSource.Range("I" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 25
'
'       Display associated names to those random #s generated
        wsSource.Range("j" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 49), 1)
    Next                                                                                ' Loop Back
'
'
'   '-----------------------------'
'   ' Display Drawing # 3 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 15                                          ' Establish loop to loop through next 15 #s randomly generated
        wsSource.Range("L" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 15
'
'       Display associated names to those random #s generated
        wsSource.Range("M" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 74), 1)
    Next                                                                                ' Loop Back
'
'
'   '-----------------------------'
'   ' Display Drawing # 4 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 8                                           ' Establish loop to loop through next 8 #s randomly generated
        wsSource.Range("O" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 8
'
'       Display associated names to those random #s generated
        wsSource.Range("P" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 89), 1)
    Next                                                                                ' Loop Back
'
'
'   '-----------------------------'
'   ' Display Drawing # 5 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 2                                           ' Establish loop to loop through last 2 #s randomly generated
        wsSource.Range("R" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 2
'
'       Display associated names to those random #s generated
        wsSource.Range("S" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 97), 1)
    Next                                                                                ' Loop Back
End Sub
Hi,

thank you for the solution.
I tried the macro, but it shows duplicate names on each draw (pink column).
And can we draw one by one for each prize, since on your macro it draw at one time for all.

Please advise.Thank you

Lucky Draw v4.xlsm
ABCDEFGHIJKLMNOPQRST
1NoNamePrize$100$200$300$400$500
21Aatifa$ 5001Kanisha1Ermina1Cassia1Naifa1Lesya
32Abida$ 4002Qeiza2Fadhila2Daryan2Nadira2Luisa
43Beatarisa$ 3003Abia3Calya3Querida3Fahimah
54Caera$ 2004Naditya4Desi4Bahzy4Lavina
65Daniza$ 1005Chalinda5Kania5Kanaya5Kalya
76Elaina6Qiandra6Davidya6Kanzia6Ababil
87Fadhila7Naava7Aatifa7Kaila7Faiha
98Cassia8Alexzandra8Eshal8Elaina8Faiha
109Abila9Luna9Kalila9Faiha
1110Alsava10Nafiza10Faakhira10Daniza
1211Davidya11Fairuz11Ceisya11Nandita
1312Faiha12Nara12Casia12Kamala
1413Baahirah13Ababil13Beatarisa13Abia
1514Abia14Faihah14Carabella14Namira
1615Danita15Qaissara15Alsava15Denta
1716Desi16Beril16Nailazaara
1817Elvaretta17Darria17Abila
1918Ababil18Qanshana18Caera
2019Badriyyah19Omkara19Desi
2120Denta20Kamaniai20Oksana
2221Calya21Cassaundra21Kanti
2322Barsha22Calandra22Abida
2423Eisha23Basmah23Davina
2524Fahimah24Opaline24Beatarisa
2625Faakhira25Badriyyah25Cadenza
2726Davina26Qaila
2827Carabella27Aazkiya
2928Darria28Danita
3029Bahzy29Abdilla
3130Aathifa30Eisha
3231Cassaundra31Adira
3332Cadenza32Aathifa
3433Ceisya33Denta
3534Basmah34Bayuni
3635Daryan35Naraya
3736Chalinda36Baahirah
3837Adira37Oriana
3938Edrea38Barsha
4039Beril39Badriyyah
4140Bayuni40Elvaretta
4241Daniza41Daniza
4342Desi42Erina
4443Badriyyah43Faihah
4544Danita44Ophelia
4645Faihah45Danita
4746Fairuz46Edrea
4847Beatarisa47Lanakila
4948Eshal48Davidya
5049Erina49Oceana
5150Calandra50Laila
5251Davidya
5352Casia
5453Abia
5554Faiha
5655Alexzandra
5756Denta
5857Ababil
5958Ermina
6059Aazkiya
6160Abdilla
6261Faiha
6362Faihah
6463Kaila
6564Kalila
6665Kalya
6766Kamala
6867Kamaniai
6968Kanaya
7069Kania
7170Kanisha
7271Kanti
7372Kanzia
7473Laila
7574Lanakila
7675Lavina
7776Lesya
7877Luisa
7978Luna
8079Naava
8180Nadira
8281Naditya
8382Nafiza
8483Naifa
8584Nailazaara
8685Namira
8786Nandita
8887Nara
8988Naraya
9089Oceana
9190Oksana
9291Omkara
9392Opaline
9493Ophelia
9594Oriana
9695Qaila
9796Qaissara
9897Qanshana
9998Qeiza
10099Qiandra
101100Querida
Data
Cells with Conditional Formatting
CellConditionCell FormatStop If True
P2:P1048576Cell ValueduplicatestextNO
M2:M1048576Cell ValueduplicatestextNO
J2:J1048576Cell ValueduplicatestextNO
G2:G1048576Cell ValueduplicatestextNO
B2:B41Cell ValueduplicatestextNO
B2:B21Cell ValueduplicatestextNO
A2:A101Cell ValueduplicatestextNO
A2:A101Cell ValueduplicatestextNO
G2:G33,G94:G1048576Cell ValueduplicatestextNO
G2:G13,G94:G1048576Cell ValueduplicatestextNO
 
Upvote 0
thank you for the solution.
I tried the macro, but it shows duplicate names on each draw (pink column).

There is a phrase in the computer world of GIGO. It stands for Garbage In Garbage Out.

You are not seeing 'duplicates' in the sense that you are implying. You are seeing different employees with the same name.

Your list of employees is where the 'duplicates' originate from.
VBA Code:
Badriyyah   - #19, #43
Beatarisa   - #3,  #47
Danita      - #15, #44
Desi        - #16, #42
Faiha       - #12, #54, #61
Faihah      - #45, #62

I don't believe that it is possible for the code that I provided to produce duplicates, provided that each drawing is chopped up properly, which it is.


Now on to your question. You asked if the code could be done to 'draw one by one for each prize'. I need some clarification there. Are you asking for a separate display for each employee, meaning 100 separate displays? Are you asking for a separate display for each prize category, meaning all of the $100 winners displayed, then $200 winners, etc?

Please clarify what you are asking.
 
Upvote 0
There is a phrase in the computer world of GIGO. It stands for Garbage In Garbage Out.

You are not seeing 'duplicates' in the sense that you are implying. You are seeing different employees with the same name.

Your list of employees is where the 'duplicates' originate from.
VBA Code:
Badriyyah   - #19, #43
Beatarisa   - #3,  #47
Danita      - #15, #44
Desi        - #16, #42
Faiha       - #12, #54, #61
Faihah      - #45, #62

I don't believe that it is possible for the code that I provided to produce duplicates, provided that each drawing is chopped up properly, which it is.


Now on to your question. You asked if the code could be done to 'draw one by one for each prize'. I need some clarification there. Are you asking for a separate display for each employee, meaning 100 separate displays? Are you asking for a separate display for each prize category, meaning all of the $100 winners displayed, then $200 winners, etc?

Please clarify what you are asking.
Noted on the duplicate names. My bad not checked the origin data.

I’m asking for separate display for each prize category. All of $100 winners displayed, then $200 winners, etc.

Please advise. Thankyou
 
Upvote 0
Ok. Try this:

VBA Code:
#If VBA7 Then
    Public Declare PtrSafe Function ModelessMsgBox Lib "User32" Alias "MessageBoxA" (Optional ByVal hWnd As Long, _
            Optional ByVal prompt As String, _
            Optional ByVal title As String, _
            Optional ByVal buttons As Long) As Long
#Else
    Public Declare Function ModelessMsgBox Lib "User32" Alias "MessageBoxA" (Optional ByVal hWnd As Long, _
            Optional ByVal prompt As String, _
            Optional ByVal title As String, _
            Optional ByVal buttons As Long) As Long
#End If

Sub Name_Prize_GeneratorV2()
'
    Dim LastRow                             As Long
    Dim RandomEmployeeNumberPicked          As Long, RandomEmployeeNumberPickedCounter  As Long, RandomNumberGeneratedCounter   As Long
    Dim RandomEmployeeNumberPickedArray     As Object
    Dim EmployeeArray                       As Variant
    Dim wsSource                            As Worksheet
'
    Set wsSource = Sheets("Sheet3")                                                     ' <--- Set this to the sheet name that contains the employee list
'
    LastRow = wsSource.Range("B" & Rows.Count).End(xlUp).Row                            ' Get Last Row Number of employee names
'
    EmployeeArray = wsSource.Range("B2:B" & LastRow)                                    ' Load Employee names into a 2D 1 based array RC
'
    Set RandomEmployeeNumberPickedArray = CreateObject("Scripting.Dictionary")          ' Establish Dictionary Array
'
    RandomEmployeeNumberPickedCounter = 1                                               ' Initialize RandomEmployeeNumberPickedCounter
'
    wsSource.Range("F2:S52").ClearContents                                              ' Erase the Results area
'
'
'   '-----------------------------'
'   ' Generate the random numbers '
'   '-----------------------------'
'
    While RandomEmployeeNumberPickedArray.Count < 100                                   ' Establish loop to generate 100 unique random numbers ... 1 to 100
        RandomEmployeeNumberPicked = Application.WorksheetFunction.RandBetween(1, 100)  '   Generate random number between 1 & 100
'
        If Not RandomEmployeeNumberPickedArray.Exists(RandomEmployeeNumberPicked) Then  '   If this is a unique random # then ...
            RandomEmployeeNumberPickedArray.Add RandomEmployeeNumberPicked, RandomEmployeeNumberPickedCounter   '       Save the number into dictionary array
            RandomEmployeeNumberPickedCounter = RandomEmployeeNumberPickedCounter + 1   '       Increment the RandomEmployeeNumberPickedCounter
        End If
    Wend                                                                                ' Loop back
'
'
'   '-----------------------------'
'   ' Display Drawing # 1 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 50                                          ' Establish loop to loop through first 50 #s randomly generated
        wsSource.Range("F" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 50
'
'       Display associated names to those random #s generated
        wsSource.Range("G" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter - 1), 1)
    Next                                                                                ' Loop Back
'
    For I = 1 To 5                                                                      ' Use a loop to allow time for results to display ... increase if needed
        DoEvents
    Next I
'
    If ModelessMsgBox(prompt:=Space(27) & "$100 Prize winners have have been displayed." & vbCrLf & vbCrLf & "Press the 'OK' button when you " & _
        "are ready to display the $200 prize winners.", title:=Space(33) & "Program paused to allow scrolling.", buttons:=vbOK) <> 1 Then Exit Sub
'
'
'   '-----------------------------'
'   ' Display Drawing # 2 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 25                                          ' Establish loop to loop through next 25 #s randomly generated
        wsSource.Range("I" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 25
'
'       Display associated names to those random #s generated
        wsSource.Range("j" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 49), 1)
    Next                                                                                ' Loop Back
'
    For I = 1 To 5                                                                      ' Use a loop to allow time for results to display ... increase if needed
        DoEvents
    Next I
'
    If ModelessMsgBox(prompt:=Space(27) & "$200 Prize winners have have been displayed." & vbCrLf & vbCrLf & "Press the 'OK' button when you " & _
        "are ready to display the $300 prize winners.", title:=Space(33) & "Program paused to allow scrolling.", buttons:=vbOK) <> 1 Then Exit Sub
'
'
'   '-----------------------------'
'   ' Display Drawing # 3 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 15                                          ' Establish loop to loop through next 15 #s randomly generated
        wsSource.Range("L" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 15
'
'       Display associated names to those random #s generated
        wsSource.Range("M" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 74), 1)
    Next                                                                                ' Loop Back
'
    For I = 1 To 5                                                                      ' Use a loop to allow time for results to display ... increase if needed
        DoEvents
    Next I
'
    If ModelessMsgBox(prompt:=Space(27) & "$300 Prize winners have have been displayed." & vbCrLf & vbCrLf & "Press the 'OK' button when you " & _
        "are ready to display the $400 prize winners.", title:=Space(33) & "Program paused to allow scrolling.", buttons:=vbOK) <> 1 Then Exit Sub
'
'
'   '-----------------------------'
'   ' Display Drawing # 4 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 8                                           ' Establish loop to loop through next 8 #s randomly generated
        wsSource.Range("O" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 8
'
'       Display associated names to those random #s generated
        wsSource.Range("P" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 89), 1)
    Next                                                                                ' Loop Back
'
    For I = 1 To 5                                                                      ' Use a loop to allow time for results to display ... increase if needed
        DoEvents
    Next I
'
    If ModelessMsgBox(prompt:=Space(27) & "$400 Prize winners have have been displayed." & vbCrLf & vbCrLf & "Press the 'OK' button when you " & _
        "are ready to display the $500 prize winners.", title:=Space(33) & "Program paused to allow scrolling.", buttons:=vbOK) <> 1 Then Exit Sub
'
'
'   '-----------------------------'
'   ' Display Drawing # 5 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 2                                           ' Establish loop to loop through last 2 #s randomly generated
        wsSource.Range("R" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 2
'
'       Display associated names to those random #s generated
        wsSource.Range("S" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 97), 1)
    Next                                                                                ' Loop Back
End Sub
 
Upvote 0
Ok. Try this:

VBA Code:
#If VBA7 Then
    Public Declare PtrSafe Function ModelessMsgBox Lib "User32" Alias "MessageBoxA" (Optional ByVal hWnd As Long, _
            Optional ByVal prompt As String, _
            Optional ByVal title As String, _
            Optional ByVal buttons As Long) As Long
#Else
    Public Declare Function ModelessMsgBox Lib "User32" Alias "MessageBoxA" (Optional ByVal hWnd As Long, _
            Optional ByVal prompt As String, _
            Optional ByVal title As String, _
            Optional ByVal buttons As Long) As Long
#End If

Sub Name_Prize_GeneratorV2()
'
    Dim LastRow                             As Long
    Dim RandomEmployeeNumberPicked          As Long, RandomEmployeeNumberPickedCounter  As Long, RandomNumberGeneratedCounter   As Long
    Dim RandomEmployeeNumberPickedArray     As Object
    Dim EmployeeArray                       As Variant
    Dim wsSource                            As Worksheet
'
    Set wsSource = Sheets("Sheet3")                                                     ' <--- Set this to the sheet name that contains the employee list
'
    LastRow = wsSource.Range("B" & Rows.Count).End(xlUp).Row                            ' Get Last Row Number of employee names
'
    EmployeeArray = wsSource.Range("B2:B" & LastRow)                                    ' Load Employee names into a 2D 1 based array RC
'
    Set RandomEmployeeNumberPickedArray = CreateObject("Scripting.Dictionary")          ' Establish Dictionary Array
'
    RandomEmployeeNumberPickedCounter = 1                                               ' Initialize RandomEmployeeNumberPickedCounter
'
    wsSource.Range("F2:S52").ClearContents                                              ' Erase the Results area
'
'
'   '-----------------------------'
'   ' Generate the random numbers '
'   '-----------------------------'
'
    While RandomEmployeeNumberPickedArray.Count < 100                                   ' Establish loop to generate 100 unique random numbers ... 1 to 100
        RandomEmployeeNumberPicked = Application.WorksheetFunction.RandBetween(1, 100)  '   Generate random number between 1 & 100
'
        If Not RandomEmployeeNumberPickedArray.Exists(RandomEmployeeNumberPicked) Then  '   If this is a unique random # then ...
            RandomEmployeeNumberPickedArray.Add RandomEmployeeNumberPicked, RandomEmployeeNumberPickedCounter   '       Save the number into dictionary array
            RandomEmployeeNumberPickedCounter = RandomEmployeeNumberPickedCounter + 1   '       Increment the RandomEmployeeNumberPickedCounter
        End If
    Wend                                                                                ' Loop back
'
'
'   '-----------------------------'
'   ' Display Drawing # 1 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 50                                          ' Establish loop to loop through first 50 #s randomly generated
        wsSource.Range("F" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 50
'
'       Display associated names to those random #s generated
        wsSource.Range("G" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter - 1), 1)
    Next                                                                                ' Loop Back
'
    For I = 1 To 5                                                                      ' Use a loop to allow time for results to display ... increase if needed
        DoEvents
    Next I
'
    If ModelessMsgBox(prompt:=Space(27) & "$100 Prize winners have have been displayed." & vbCrLf & vbCrLf & "Press the 'OK' button when you " & _
        "are ready to display the $200 prize winners.", title:=Space(33) & "Program paused to allow scrolling.", buttons:=vbOK) <> 1 Then Exit Sub
'
'
'   '-----------------------------'
'   ' Display Drawing # 2 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 25                                          ' Establish loop to loop through next 25 #s randomly generated
        wsSource.Range("I" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 25
'
'       Display associated names to those random #s generated
        wsSource.Range("j" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 49), 1)
    Next                                                                                ' Loop Back
'
    For I = 1 To 5                                                                      ' Use a loop to allow time for results to display ... increase if needed
        DoEvents
    Next I
'
    If ModelessMsgBox(prompt:=Space(27) & "$200 Prize winners have have been displayed." & vbCrLf & vbCrLf & "Press the 'OK' button when you " & _
        "are ready to display the $300 prize winners.", title:=Space(33) & "Program paused to allow scrolling.", buttons:=vbOK) <> 1 Then Exit Sub
'
'
'   '-----------------------------'
'   ' Display Drawing # 3 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 15                                          ' Establish loop to loop through next 15 #s randomly generated
        wsSource.Range("L" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 15
'
'       Display associated names to those random #s generated
        wsSource.Range("M" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 74), 1)
    Next                                                                                ' Loop Back
'
    For I = 1 To 5                                                                      ' Use a loop to allow time for results to display ... increase if needed
        DoEvents
    Next I
'
    If ModelessMsgBox(prompt:=Space(27) & "$300 Prize winners have have been displayed." & vbCrLf & vbCrLf & "Press the 'OK' button when you " & _
        "are ready to display the $400 prize winners.", title:=Space(33) & "Program paused to allow scrolling.", buttons:=vbOK) <> 1 Then Exit Sub
'
'
'   '-----------------------------'
'   ' Display Drawing # 4 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 8                                           ' Establish loop to loop through next 8 #s randomly generated
        wsSource.Range("O" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 8
'
'       Display associated names to those random #s generated
        wsSource.Range("P" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 89), 1)
    Next                                                                                ' Loop Back
'
    For I = 1 To 5                                                                      ' Use a loop to allow time for results to display ... increase if needed
        DoEvents
    Next I
'
    If ModelessMsgBox(prompt:=Space(27) & "$400 Prize winners have have been displayed." & vbCrLf & vbCrLf & "Press the 'OK' button when you " & _
        "are ready to display the $500 prize winners.", title:=Space(33) & "Program paused to allow scrolling.", buttons:=vbOK) <> 1 Then Exit Sub
'
'
'   '-----------------------------'
'   ' Display Drawing # 5 Results '
'   '-----------------------------'
'
    For RandomNumberGeneratedCounter = 1 To 2                                           ' Establish loop to loop through last 2 #s randomly generated
        wsSource.Range("R" & RandomNumberGeneratedCounter + 1).Value = RandomNumberGeneratedCounter '   Display counter of 1 - 2
'
'       Display associated names to those random #s generated
        wsSource.Range("S" & RandomNumberGeneratedCounter + 1).Value = EmployeeArray(RandomEmployeeNumberPickedArray.Keys()(RandomNumberGeneratedCounter + 97), 1)
    Next                                                                                ' Loop Back
End Sub
Hi,

thank you very much for your help.
its works. Perfect :)
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top