Hi all, I have multiple columns (A-C) of data that I am looking to analyze and group in unique pairs before outputting the pairs to new columns. All I need is unique groups of 2.
I found this awesome code from @Eric W but I cant seem to figure out how to make it loop through all my columns. It only works on the first column. Any ideas? Any help is much appreciated!
I found this awesome code from @Eric W but I cant seem to figure out how to make it loop through all my columns. It only works on the first column. Any ideas? Any help is much appreciated!
VBA Code:
Sub Subsets()
Dim MyNames As Variant, OutCell As Range, MyDic As Object, i As Long
MyNames = Range(Range("A2"), Range("A2").End(xlDown)).Value
Set OutCell = Range("C1")
For i = 1 To UBound(MyNames)
Set MyDic = CreateObject("Scripting.Dictionary")
MyDic(0) = "Sets of " & i
Call RecurSubs(MyNames, i, 0, 0, "", MyDic)
OutCell.Offset(, i - 1).Resize(MyDic.Count).Value = WorksheetFunction.Transpose(MyDic.items)
Set MyDic = Nothing
Next i
End Sub
Sub RecurSubs(ByRef MyNames, ByRef MaxLevel, ByVal CurLevel, ByVal ix, ByVal str1, ByRef MyDic)
Dim i As Long
If CurLevel = MaxLevel Then
MyDic(MyDic.Count) = Left(str1, Len(str1) - 2)
Exit Sub
End If
For i = ix + 1 To UBound(MyNames)
Call RecurSubs(MyNames, MaxLevel, CurLevel + 1, i, str1 & MyNames(i, 1) & ", ", MyDic)
Next i
End Sub