让我解释一下我想做的事情。我有一个包含两列的事件列表:事件ID和来宾。在Guests字段中,我收到了以逗号分隔的特定事件的每个参与者的电子邮件。每个活动都有不同数量的参与者。我需要的是列出每个活动的所有可能的客人组合。它看起来像这样:
在一次会议中假设参与者是A,B,C,D
这表示以下唯一的1:1连接
AB
AC
AD
BC
BD
CD
你们中的任何人都知道可以获得此输出的代码吗?
@ Gary的学生谢谢!
这就是我所拥有的,但它无法正常运作。
Sub test1()
Set l1 = Worksheets("Sheet1").Range("A1:AZ10000").Find("Event ID", lookat:=xlPart) 'Location of event id field
Set l2 = Worksheets("Sheet1").Range("A1:AZ10000").Find("Participants123", lookat:=xlPart) 'Location of guests field
Last = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Dim c As Double
Dim l As Double
l = l2.Row + 1
For i = 1 To Last
last1 = Sheet1.Cells(l, l2.Column).End(xlToRight).Column
c = Application.Combin(last1 - 3, 2)
Rows(l + 1 & ":" & l + c - 1).Insert
'Dim N As Long, i As Long, j As Long, K As Long
N = last1
K = l
For b = 4 To N - 1
For j = b + 1 To N
Cells(K, 2).Value = Cells(l, b).Value
Cells(K, 3).Value = Cells(l, j).Value
K = K + 1
Next j
Next b
l = l + c
Next i
End Sub