Im having Troubles populating a two-dimensional Array on the fly.
I have a list of 26 names and want to randomly divide them into 5 Groups of 5each, with one having 6. I then want to use each Group to write the names into a separate sheet. My Background is PHP and JS, so the Need to dim or redim an Array doesnt come as easy to me.
Dim KlasseA() As String
Dim KlasseB() As String
Dim KlasseC() As String
Dim KlasseD() As String
Dim KlasseE() As String
For i = 1 To 20
If Sheets(1).Cells(i + 1, 2) <> "" Then
pick = ((5 - 1 + 1) * Rnd + 1)
If pick = 1 Then
KlasseA(i) = Sheets(1).Cells(i + 1, 3) & ", " & Sheets(1).Cells(i + 1, 2)
ElseIf pick = 2 Then
KlasseB(i) = Sheets(1).Cells(i + 1, 3) & ", " & Sheets(1).Cells(i + 1, 2)
ElseIf pick = 3 Then
KlasseC(i) = Sheets(1).Cells(i + 1, 3) & ", " & Sheets(1).Cells(i + 1, 2)
ElseIf pick = 4 Then
KlasseD(i) = Sheets(1).Cells(i + 1, 3) & ", " & Sheets(1).Cells(i + 1, 2)
ElseIf pick = 5 Then
KlasseE(i) = Sheets(1).Cells(i + 1, 3) & ", " & Sheets(1).Cells(i + 1, 2)
End If
Else
Exit For
End If
Next i
' push the 5 Arrays into a master Array. Use 1 Loop inside a Loop Output the 5 Groups to 5 sheets
Im having two Problems here:
How can i create "higher" Array where i can push the 5 lower Arrays into, to then Loop over all the names (i.e. one final Loop instead of 5).
The code above will populate the sub-Arrays in a non-fluid manner, i.e. a bunch of array-index are left out (due to the i).
Ideally, i would want to create a 2d-Array and use this inside the Loop instead of the flawed workaround above. Can someone advice me ?