Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Need a format for team vs team | Excel Discussion (Misc queries) | |||
Team Role Rotation (number of team members is variable) | Excel Worksheet Functions | |||
team schedule | Setting up and Configuration of Excel | |||
team standings | Excel Discussion (Misc queries) | |||
how do i do a dream team | New Users to Excel |