Generating unique combination

BigBeachBananas

Board Regular
Hi,
I have the following VBA code from @Peter_SSs from another thread that generates unique combinations. However, the VBA omits combinations with repeated elements. For example, if I have elements A, B, and C then AA, BB, CC are omitted. I'm looking for some help modifying the VBA such that it retains the combinations with repeated elements. Thanks!

VBA Code:
``````Sub All2Combos()
Dim a As Variant, b As Variant
Dim i As Long, j As Long, x As Long, y As Long

a = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value
ReDim b(1 To UBound(a))
For i = 1 To UBound(a)
If Len(a(i, 1)) > 0 Then
x = x + 1: b(x) = a(i, 1)
End If
Next i
ReDim a(1 To WorksheetFunction.Combin(x, 2), 1 To 1)
For i = 1 To x - 1
For j = i + 1 To x
y = y + 1: a(y, 1) = b(i) & b(j)
Next j
Next i
Range("C2").Resize(y).Value = a
End Sub``````

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Replies
4
Views
131
Replies
9
Views
689
Replies
4
Views
140
Replies
5
Views
294
Replies
4
Views
57

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,151,767
Messages
5,766,359
Members
425,350
Latest member
procha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back