Sub DistributeEmployeesToGroups() Dim LastRow As Long Dim i As Long, j As Long Dim PresentationCount(5) As Long Dim GroupCounter As Long LastRow = Cells(Rows.Count, "A").End(xlUp).Row ' Initialize PresentationCount array For i = 1 To 5 PresentationCount(i) = 0 Next i ' Loop through employees For i = 2 To LastRow ' Loop through preferences For j = 2 To 6 Dim Pref As Long Pref = Cells(i, j).Value ' Check if the presentation is already assigned to 3 groups If PresentationCount(Pref) < 3 Then ' Assign the employee to the group GroupCounter = GroupCounter Mod 10 + 1 Cells(i, j + 5).Value = GroupCounter PresentationCount(Pref) = PresentationCount(Pref) + 1 Exit For End If Next j Next i End Sub