David,
I have developed a macro that does just that, though it does not optimize meeting attendance. By
that I mean, if a lot of people choose one specific meeting or class as their #3 choice, it will not
preferentially select those folks just to fill up the class - that is a judgement call on your part.
This is strictly based on attendee preferences, randomized to make it fair. To optimize class size
or to fill up other classes, you may need some manual intervention.
Anyway, let's say that you have three meetings.
In cells B1:D1, enter the maximum allowed meeting size for the session.
In cells B2:D2, enter the meeting names. In E2, enter the word "Randomize" and in F2, "Assigned to"
Then in B3:D3, enter 0. In cell E3, enter -1.
Then starting in A4, enter the name, and in cells B4:D4, the preference numbers. In cell E4, enter
the formula =RAND()
Continue down columns A through D with the names and preferences, and copy the formula in E4 down
column E to match your database.
Then save it, and run the macro below.
Note that this can be expanded for as many meetings as you have by inserting extra columns before
the column with the =RAND() formulas.
If the participants can have more than three choices, increase the 3 of the
For myChoice = 1 To 3
to match the maximum number of choices.
If you want to manually fill meetings, enter the values in the "Assigned to" column.
If you have a problem, email me privately and I will send you a working example.
HTH,
Bernie
MS Excel MVP
Sub AssignToSession()
Dim i As Integer
Dim j As Integer
Dim myChoice As Integer
Dim myC As Integer
Dim myR As Range
Dim myV As Range
Set myR = Intersect(Range("2:65536"), Range("A2").CurrentRegion)
On Error Resume Next
ActiveSheet.ShowAllData
myC = Range("IV1").End(xlToLeft).Column
For myChoice = 1 To 3
For i = 2 To myC
myR.Sort key1:=Cells(2, i), order1:=xlAscending, _
key2:=Cells(2, myC + 2), order2:=xlAscending, _
key3:=Cells(2, myC), order3:=xlAscending, header:=xlYes
myR.AutoFilter Field:=i, Criteria1:=myChoice
myR.AutoFilter Field:=myC + 2, Criteria1:="="
Set myV = myR.Columns(i).SpecialCells(xlCellTypeVisible)
If Cells(1, i).Value > 0 Then
If myV.Areas(2).Rows.Count < Cells(1, i).Value Then
myV.Areas(2).Offset(0, myC - i + 2).Value = myR(1, i).Value
Cells(1, i).Value = Cells(1, i).Value - myV.Areas(2).Rows.Count
Else
myV.Areas(2).Offset(0, myC - i + 2). _
Resize(Cells(1, i).Value).Value = myR(1, i).Value
Cells(1, i).Value = 0
End If
End If
myR.AutoFilter
Next i
Next myChoice
End Sub
> Hi there,
>
[quoted text clipped - 25 lines]
>
> Many thanks - David
Daveo - 22 Sep 2006 12:12 GMT
Hi Bernie,
Worked a treat!
Many thanks,
David
skatonni - 22 Sep 2006 14:30 GMT
Bernie
I think I followed the instructions but it appears there ia a typo i
this part of the code.
Code
-------------------
myR.Sort key1:=Cells(2, i), order1:=xlAscending, _
key2:=Cells(2, myC + 2), order2:=xlAscending, _
key3:=Cells(2, myC), order3:=xlAscending, header:=xlYe
-------------------
I cannot see a random factor unless I change key3.
Code
-------------------
myR.Sort Key1:=Cells(2, i), Order1:=xlAscending, _
key2:=Cells(2, myC + 2), order2:=xlAscending, _
key3:=Cells(2, myC + 1), order3:=xlAscending, Header:=xlYe
-------------------
--
skatonn
Posted from - http://www.officehelp.i
Bernie Deitrick - 22 Sep 2006 15:55 GMT
Thanks! Good catch!
You're right, and you get a gold star for paying better attention than me....
Bernie
MS Excel MVP
> Bernie
>
[quoted text clipped - 16 lines]
> key3:=Cells(2, myC + 1), order3:=xlAscending, Header:=xlYes
> --------------------