DonKampfello
New Member
- Joined
- Apr 18, 2022
- Messages
- 13
- Office Version
- 365
- Platform
- Windows
Hi Excel geniuses
I need help with generating unique combinations of values in 1 column:
A ("Width")
0.660
0.742
0.825
0.990
1.155
1.237
1.253
I have used the Code given by the following user. It generated the values in the orange table, which worked out okay:
However, I have encountered 3 problems:
1. The combinations are stored together in one single cell. I need them separated in different columns, so I can make a sum total of the combinations. The Blue table is my end goal.
2. The VBA code does not allow each input from the yellow column ("A") to be used more than once. I need each width to be used more than once.
3. I need a constraint inside the VBA code, so only combinations with sum total = < 3,850 are generated. Is this possible?
I made The Blue table manually to illustrate my end goal. I hope the task makes sense.
I need help with generating unique combinations of values in 1 column:
A ("Width")
0.660
0.742
0.825
0.990
1.155
1.237
1.253
I have used the Code given by the following user. It generated the values in the orange table, which worked out okay:
Need all unique combinations of a single column
I need to create a list of unique name combinations from a single column, for example: Mary Jim Henry Candy And output all unique combinations but also grouped up to the number of names. E.G. Mary + Jim, Mary + Jim + Henry, etc. The name column may vary in total names. Perhaps output one...
www.mrexcel.com
However, I have encountered 3 problems:
1. The combinations are stored together in one single cell. I need them separated in different columns, so I can make a sum total of the combinations. The Blue table is my end goal.
2. The VBA code does not allow each input from the yellow column ("A") to be used more than once. I need each width to be used more than once.
3. I need a constraint inside the VBA code, so only combinations with sum total = < 3,850 are generated. Is this possible?
I made The Blue table manually to illustrate my end goal. I hope the task makes sense.
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 6
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