2017-08-28 13 views
-1

因此,讓我解釋我正在嘗試做什麼。我有兩列的事件列表:Event ID和Guests。在嘉賓字段中,我有用逗號分隔的特定事件的每個參與者的電子郵件。每個事件都有不同數量的參與者。我需要的是列出每個活動的所有可能的賓客組合。它看起來是這樣的:如何在由逗號分隔的單元格中創建可能的字符串組合列表

假設在一個會議的與會者是A,B,C,d

這代表了以下獨特的1:1個連接

AB 
AC 
AD 
BC 
BD 
CD 

做任何你知道可以得到這個輸出的代碼?

@加里的學生謝謝!

這是我的,但它不能正常工作。

Excel table

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 

! (http://imgur.com/72nW9uR

+0

你有算法或代碼問題嗎?如果是第一個 - 如果第二個問題告訴我們你做了什麼,這是不適合的地方。 – avb

回答

2

放置在列A的名稱和運行是這樣的:

Sub dural() 
Dim N As Long, i As Long, j As Long, K As Long 
    N = 4 
    K = 1 
    For i = 1 To N - 1 
     For j = i + 1 To N 
      Cells(K, 2).Value = Cells(i, 1).Value & Cells(j, 1).Value 
      K = K + 1 
     Next j 
    Next i 
End Sub 

enter image description here

這是假設你只需要對這樣ABC不考慮。還假定ABBA是相同的。

+0

比你加里!我試圖調整代碼,但沒有理由不起作用。你可以在上面的文章中看到我有什麼。請讓我知道,如果你有任何想法,爲什麼代碼不工作! – Alex

相關問題