Disclaimer: It is really a good idea to read the rules in StackOverflow concerning asking a question and to give some code, when you are trying to solve a problem. StackOverflow is not a free coding service and etc.
Howerver, at least you took screenshots, which is something. In a way.
As a next step try to pass the values of the Excel cells to arrays or lists (whatever you want). In my case, I have hardcoded them as group1
and group4
. The groups are consistent of numbers and not of names, because it is a bit faster this way and more understandable. In your example you may consider remapping them back at the end:
Public Sub TestMe()
Dim group1, group4
Dim groupOfAll, group
Dim student
Dim cnt As Long
Dim cnt2 As Long
group1 = Array(1, 2, 3)
group4 = Array(4, 5, 6, 7)
groupOfAll = Array(group1, group4)
For Each group In groupOfAll
cnt2 = 1
For Each student In group
For cnt = LBound(group) + cnt2 To UBound(group)
Debug.Print student; "<>"; group(cnt)
Next cnt
cnt2 = cnt2 + 1
Next student
Debug.Print "----party------"
Next group
End Sub
The tricky part in the code is that you loop every person per group, but after you finish with the first person you do not loop through him again. This is achieved with For cnt = LBound(group) + cnt2 To UBound(group)
and the cnt2=cnt2+1
. cnt2 = 1
, because we start with the first element from the Array in position 0, and we "introduce" this student to the next one. This is the result:
1 <> 2
1 <> 3
2 <> 3
----party------
4 <> 5
4 <> 6
4 <> 7
5 <> 6
5 <> 7
6 <> 7
----party------