Sub DivideTeams()
Dim TeamList As Variant
Dim SourceTeam As Range
Dim TeamCount As Long
Dim recCount As Long
Dim evenDiv As Long
Dim extraRecs As Long
Dim lastRow As Long
Dim lastCol As Long
Dim teamChoice As Long
Dim i As Long
Dim j As Long
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim lastRow1 As Long
Dim lastRow2 As Long
Application.ScreenUpdating = False
Set ws1 = Sheets("Team")
Set ws3 = Sheets("Consolidation Tracker")
With ws1
lastRow1 = .Cells(.Rows.Count, "A").End(xlUp).Row
lastRow2 = Sheets("In Team").Range("A:A").End(xlUp).Row
For i = 5 To lastRow1
lastRow2 = Sheets("In Team").Range("A:A").End(xlUp).Row
If .Cells(i, 2) = "In" Then .Cells(i, 1).Copy Destination:=Sheets("In Team").Range("A100").End(xlUp)(2, 1)
Next i
End With
'Who are the teams?
'TeamList = Array("Team A", "Team B", "Team C", "Team D", "Team E", "Team F")
Set SourceTeam = Sheets("In Team").Range("A1:A5")
TeamList = SourceTeam.Value
teamChoice = 1
TeamCount = UBound(TeamList)
i = 1
'Make new workbook
ws3.Copy
'ActiveSheet.Copy
With ActiveSheet
'Math calculations
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
'Always find the first blank column
lastCol = .Cells(1, Columns.Count).End(xlToLeft).Column + 1
recCount = lastRow - 1
extraRecs = recCount Mod TeamCount
evenDiv = (recCount - extraRecs) / TeamCount
Do While i < lastRow
'Every team gets at least the same amount
For j = 1 To evenDiv
i = i + 1
'since TeamList is from a range, it's now a 2D array, so needs 2 arguments
.Cells(i, lastCol).Value = TeamList(teamChoice, 1)
Next j
'Check if uneven amount, and if so, add a line
If j = evenDiv + 1 And extraRecs > 0 Then
i = i + 1
.Cells(i, lastCol).Value = TeamList(teamChoice, 1)
extraRecs = extraRecs - 1
End If
'Next team queued up
teamChoice = teamChoice + 1
Loop
.Cells(1, lastCol).Value = "Assigned to"
End With
Application.ScreenUpdating = True
End Sub