Produce all combinations from a list of names in excel

前端 未结 1 1711
青春惊慌失措
青春惊慌失措 2021-01-25 12:38

So I already have the list of permutations, but i\'d like to convert it to combinations. So i have a single list of names \"john\" \"mike\" \"tom\", and these have already been

1条回答
  •  情歌与酒
    2021-01-25 12:54

    Try this:

    Sub NoRepetition()
    
    Dim NameList As Variant, NameVal As Variant, NameVal2 As Variant
    Dim Iter As Long, OutputList As Range, NotYet As Boolean
    
    NameList = Range("A1:A5").Value
    
    Iter = 1
    For Each NameVal In NameList
        For Each NameVal2 In NameList
            LRow = Range("C" & Rows.Count).End(xlUp).Row
            Set OutputList = Range("C1:C" & LRow)
            NotYet = (Application.CountIf(OutputList, NameVal2) = 0)
            If NameVal2 <> NameVal And NotYet Then
                Range("C" & Iter).Value = NameVal
                Range("D" & Iter).Value = NameVal2
                Iter = Iter + 1
            End If
        Next NameVal2
    Next NameVal
    
    End Sub
    

    The additional concept is simple: just add a check to see if the name already exists in the first column. If it does, skip that combination. If not, put it in.

    Screenshot:

    enter image description here

    Let us know if this helps.

    0 讨论(0)
提交回复
热议问题