![]() |
can it be adopted for a 16 team 4 group?
Hi,
Below is a code from Jim Cone which provides a way of drawing arbitrary names from a bag. I need to adopt this code such that it can be used to establish 4 groups (A,B,C and D each having 4 teams) out of 16 team. The only problem is that I need to select 4 teams out of the 16 team before I start drawing. Can you suggest solutions? TIA ============================== 'July 06, 2004 - Jim Cone Sub DisplayRandomNames() Dim RS As Long Dim objRangeA As Range Dim objRangeB As Range Dim objRangeC As Range Dim blnNotThere As Boolean ' Establish where everything goes or comes from. Set objRangeA = Worksheets(1).Range("A1:A35") Set objRangeB = Worksheets(2).Range("B1:B35") Set objRangeC = Worksheets(2).Range("C1:C35") ' Is there anything to work with? If WorksheetFunction.CountA(objRangeA) < 35 Then MsgBox "Kaynak listenin eksik olduğu sayfa " & objRangeA.Parent.Name & " ", _ vbExclamation, " Maksimum 35 olmalıydı" GoTo DontCallMe End If Worksheets(2).Select StartOver: ' If objRangeC range is blank then fill ' with names, clear Columns 1 and 2 and exit. If WorksheetFunction.CountA(objRangeC) = 0 Then objRangeC.Value = objRangeA.Value objRangeC.Columns.AutoFit objRangeB.ClearContents objRangeB.ColumnWidth = objRangeC.ColumnWidth 'Range("A1").ClearContents Range("A1").ColumnWidth = objRangeC.ColumnWidth GoTo DontCallMe End If ' Keep looking until random name is found in objRangeC. Do While blnNotThere = False Randomize RS = Int(Rnd * 35 + 1) 'Find RS position within objRangeC. If Not IsError(Application.Match(objRangeC(RS), objRangeC, 0)) Then blnNotThere = True Range("A1").Value = objRangeC(RS) objRangeB(WorksheetFunction.CountA(objRangeB) + 1).Value = objRangeC(RS) objRangeC(Application.Match(objRangeC(RS), objRangeC, 0)).Delete shift:=xlUp End If Loop ' Are you bored yet? If WorksheetFunction.CountA(objRangeC) = 0 Then If MsgBox("İşlem Tamam! .. Tekrar? ", vbQuestion + vbYesNo, _ " Rastgele isim Kurası") = vbYes Then GoTo StartOver End If DontCallMe: Set objRangeA = Nothing Set objRangeB = Nothing Set objRangeC = Nothing End Sub |
can it be adopted for a 16 team 4 group?
Sorry the subject should have been "can it be adopted for a 4 group each
having 4 teams?" "Martyn" wrote in message ... Hi, Below is a code from Jim Cone which provides a way of drawing arbitrary names from a bag. I need to adopt this code such that it can be used to establish 4 groups (A,B,C and D each having 4 teams) out of 16 team. The only problem is that I need to select 4 teams out of the 16 team before I start drawing. Can you suggest solutions? TIA ============================== 'July 06, 2004 - Jim Cone Sub DisplayRandomNames() Dim RS As Long Dim objRangeA As Range Dim objRangeB As Range Dim objRangeC As Range Dim blnNotThere As Boolean ' Establish where everything goes or comes from. Set objRangeA = Worksheets(1).Range("A1:A35") Set objRangeB = Worksheets(2).Range("B1:B35") Set objRangeC = Worksheets(2).Range("C1:C35") ' Is there anything to work with? If WorksheetFunction.CountA(objRangeA) < 35 Then MsgBox "Kaynak listenin eksik olduğu sayfa " & objRangeA.Parent.Name & " ", _ vbExclamation, " Maksimum 35 olmalıydı" GoTo DontCallMe End If Worksheets(2).Select StartOver: ' If objRangeC range is blank then fill ' with names, clear Columns 1 and 2 and exit. If WorksheetFunction.CountA(objRangeC) = 0 Then objRangeC.Value = objRangeA.Value objRangeC.Columns.AutoFit objRangeB.ClearContents objRangeB.ColumnWidth = objRangeC.ColumnWidth 'Range("A1").ClearContents Range("A1").ColumnWidth = objRangeC.ColumnWidth GoTo DontCallMe End If ' Keep looking until random name is found in objRangeC. Do While blnNotThere = False Randomize RS = Int(Rnd * 35 + 1) 'Find RS position within objRangeC. If Not IsError(Application.Match(objRangeC(RS), objRangeC, 0)) Then blnNotThere = True Range("A1").Value = objRangeC(RS) objRangeB(WorksheetFunction.CountA(objRangeB) + 1).Value = objRangeC(RS) objRangeC(Application.Match(objRangeC(RS), objRangeC, 0)).Delete shift:=xlUp End If Loop ' Are you bored yet? If WorksheetFunction.CountA(objRangeC) = 0 Then If MsgBox("İşlem Tamam! .. Tekrar? ", vbQuestion + vbYesNo, _ " Rastgele isim Kurası") = vbYes Then GoTo StartOver End If DontCallMe: Set objRangeA = Nothing Set objRangeB = Nothing Set objRangeC = Nothing End Sub |
All times are GMT +1. The time now is 08:41 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com