There were a couple conversations on here regarding VBA code to find all possible combinations among multiple columns with varying lengths of data in Excel. The conversations included 3, 4, and 5 columns, but I need to do this with 14 columns. The 5 column code given in this conversation is what I used: VBA - Write all possible combinations of 4 columns of data But I'm getting the following error: "Run-time error '6': Overflow" and it highlights this line when I go to debug:
Set out1 = Range("G2", Range("K2").Offset(UBound(c1) * UBound(c2) * UBound(c3) * UBound(c4) * UBound(c5) * UBound(c6) * UBound(c7) * UBound(c8) * UBound(c9) * UBound(c10) * UBound(c11) * UBound(c12) * UBound(c13) * UBound(c14)))
Here is the full code I tweaked from the example I found for 5 columns:
Sub combinations()
Dim c1() As Variant
Dim c2() As Variant
Dim c3() As Variant
Dim c4() As Variant
Dim c5() As Variant
Dim c6() As Variant
Dim c7() As Variant
Dim c8() As Variant
Dim c9() As Variant
Dim c10() As Variant
Dim c11() As Variant
Dim c12() As Variant
Dim c13() As Variant
Dim c14() As Variant
Dim out() As Variant
Dim j, k, l, m, n, o, p, q, r, s, t, u, v, w, x As Long
Dim col1 As Range
Dim col2 As Range
Dim col3 As Range
Dim col4 As Range
Dim col5 As Range
Dim col6 As Range
Dim col7 As Range
Dim col8 As Range
Dim col9 As Range
Dim col10 As Range
Dim col11 As Range
Dim col12 As Range
Dim col13 As Range
Dim col14 As Range
Dim out1 As Range
Set col1 = Range("A66", Range("A66").End(xlDown))
Set col2 = Range("B66", Range("B66").End(xlDown))
Set col3 = Range("C66", Range("C66").End(xlDown))
Set col4 = Range("D66", Range("D66").End(xlDown))
Set col5 = Range("E66", Range("E66").End(xlDown))
Set col6 = Range("F66", Range("F66").End(xlDown))
Set col7 = Range("G66", Range("G66").End(xlDown))
Set col8 = Range("H66", Range("H66").End(xlDown))
Set col9 = Range("I66", Range("I66").End(xlDown))
Set col10 = Range("J66", Range("J66").End(xlDown))
Set col11 = Range("K66", Range("K66").End(xlDown))
Set col12 = Range("L66", Range("L66").End(xlDown))
Set col13 = Range("M66", Range("M66").End(xlDown))
Set col14 = Range("N66", Range("N66").End(xlDown))
c1 = col1
c2 = col2
c3 = col3
c4 = col4
c5 = col5
c6 = col6
c7 = col7
c8 = col8
c9 = col9
c10 = col10
c11 = col11
c12 = col12
c13 = col13
c14 = col14
Set out1 = Range("P66", Range("AC66").Offset(UBound(c1) * UBound(c2) * UBound(c3) * UBound(c4) * UBound(c5) * UBound(c6) * UBound(c7) * UBound(c8) * UBound(c9) * UBound(c10) * UBound(c11) * UBound(c12) * UBound(c13) * UBound(c14)))
out = out1
j = 1
k = 1
l = 1
m = 1
n = 1
o = 1
p = 1
q = 1
r = 1
s = 1
t = 1
u = 1
v = 1
w = 1
x = 1
Do While j <= UBound(c1)
Do While k <= UBound(c2)
Do While l <= UBound(c3)
Do While m <= UBound(c4)
Do While n <= UBound(c5)
Do While o <= UBound(c6)
Do While p <= UBound(c7)
Do While q <= UBound(c8)
Do While r <= UBound(c9)
Do While s <= UBound(c10)
Do While t <= UBound(c11)
Do While u <= UBound(c12)
Do While v <= UBound(c13)
Do While w <= UBound(c14)
out(o, 1) = c1(j, 1)
out(o, 2) = c2(k, 1)
out(o, 3) = c3(l, 1)
out(o, 4) = c4(m, 1)
out(o, 5) = c5(n, 1)
out(o, 6) = c6(o, 1)
out(o, 7) = c7(p, 1)
out(o, 8) = c8(q, 1)
out(o, 9) = c9(r, 1)
out(o, 10) = c10(s, 1)
out(o, 11) = c11(t, 1)
out(o, 12) = c12(u, 1)
out(o, 13) = c13(v, 1)
out(o, 14) = c14(w, 1)
x = x + 1
w = w + 1
Loop
w = 1
v = v + 1
Loop
v = 1
u = u + 1
Loop
u = 1
t = t + 1
Loop
t = 1
s = s + 1
Loop
s = 1
r = r + 1
Loop
r = 1
q = q + 1
Loop
q = 1
p = p + 1
Loop
p = 1
o = o + 1
Loop
o = 1
n = n + 1
Loop
n = 1
m = m + 1
Loop
m = 1
l = l + 1
Loop
l = 1
k = k + 1
Loop
k = 1
j = j + 1
Loop
out1.Value = out
End Sub
Also, as a note, I tried tweaking the code so that my input started at the top of the spreadsheet (A1 vice the A66 I currently have), and that didn't help. Additionally, I know in the original code I used as reference it lists "Dim j As Long, k As Long, l As Long, etc.) and I shortened it, but I had originally used the long-form and still got the error. Any assistance would be greatly appreciated. I am a total amateur with VBA, so my apologies if the error is obvious. I have tried to research the error code, but I cannot find why mine specifically is messing up. Thanks very much for your time.
Very Respectfully, T.