Samantha27
New Member
- Joined
- Jan 30, 2024
- Messages
- 7
- Office Version
- 2016
- Platform
- Windows
Hello Good People,
I have this allocation workbook that when I click a button. It will randomly divide the list of data into 8. (Currently 8 but it will soon increase).
I have attached a sample images for my 2 sheets.
Persons sheet - List of data
Teams sheet - Output of allocation
However, I'm having a problem with this line of code
Also, it only set to 10 and should exclude the header of Persons sheet whenever I click the button.
What I wanted to achieve is to divide the data randomly and evenly to the 8 employee.
Below is my full code. Hoping someone could help me on this, Thank youuuu guys in advance.
I have this allocation workbook that when I click a button. It will randomly divide the list of data into 8. (Currently 8 but it will soon increase).
I have attached a sample images for my 2 sheets.
Persons sheet - List of data
Teams sheet - Output of allocation
However, I'm having a problem with this line of code
VBA Code:
teamsSheet.Cells(startRow, startCol).Value = personsSheet.Cells(personNumber, 2).Value
Also, it only set to 10 and should exclude the header of Persons sheet whenever I click the button.
What I wanted to achieve is to divide the data randomly and evenly to the 8 employee.
Below is my full code. Hoping someone could help me on this, Thank youuuu guys in advance.
VBA Code:
Public Sub CreateTeams_BtnClick()
CreateTeams
End Sub
Private Sub CreateTeams()
Dim teamsSheet, personsSheet As Worksheet
Set teamsSheet = Worksheets("Teams")
Set personsSheet = Worksheets("Persons")
personsSheet.Range("A:A").Copy Destination:=personsSheet.Range("B:B")
Dim numPersons As Integer
numPersons = personsSheet.Range("B:B").End(xlDown).Row
Dim startRow As Integer
startRow = 2
Dim startCol As Integer
startCol = 1
Dim personNumber As Integer
For i = 2 To 8
For j = 1 To 10
personNumber = Int((numPersons - 1 + 1) * Rnd() + 1)
teamsSheet.Cells(startRow, startCol).Value = personsSheet.Cells(personNumber, 2).Value
personsSheet.Cells(personNumber, 2).Delete Shift:=xlUp
numPersons = numPersons - 1
startRow = startRow + 1
Next j
If i < 8 Then
startRow = 2
startCol = startCol + 1
ElseIf i = 8 Then
startRow = 14
startCol = 1
Else
startRow = 14
startCol = startCol + 1
End If
Next i
End Sub