This script should be combining 2 sets of four columns each of cells and printing each combination on the adjacent cells. I have had this working for 2 sets of three cells, but now I am getting a
1004 Application Defined or Object Defined erorr
It highlights:
Set out_1 = Range("I1", Range("L1").Offset(UBound(c1) * UBound(c2) * UBound(c3) * UBound(c7)))
I am not really sure how to fix this, can anyone help?
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 out1() As Variant
Dim out2() As Variant
Dim j, k, l, m, n 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 out_1 As Range
Dim out_2 As Range
Set col1 = Range("A1", Range("A1").End(xlDown))
Set col2 = Range("C1", Range("C1").End(xlDown))
Set col3 = Range("E1", Range("E1").End(xlDown))
Set col4 = Range("B1", Range("B1").End(xlDown))
Set col5 = Range("D1", Range("D1").End(xlDown))
Set col6 = Range("F1", Range("F1").End(xlDown))
Set col7 = Range("G1", Range("G1").End(xlDown))
Set col8 = Range("H1", Range("H1").End(xlDown))
c1 = col1
c2 = col2
c3 = col3
c4 = col4
c5 = col5
c6 = col6
c7 = col7
c8 = col8
Set out_1 = Range("I1", Range("L1").Offset(UBound(c1) * UBound(c2) * UBound(c3) * UBound(c7)))
Set out_2 = Range("M1", Range("P1").Offset(UBound(c4) * UBound(c5) * UBound(c6) * UBound(c8)))
out1 = out_1
out2 = out_2
j = 1
k = 1
l = 1
m = 1
n = 1
Do While j <= UBound(c1)
Do While k <= UBound(c2)
Do While l <= UBound(c3)
Do While m <= UBound(c7)
out1(n, 1) = c1(j, 1)
out1(n, 2) = c2(k, 1)
out1(n, 3) = c3(l, 1)
out1(n, 4) = c7(m, 1)
n = n + 1
m = m + 1
Loop
m = m
l = l + 1
Loop
l = 1
k = k + 1
Loop
k = 1
j = j + 1
Loop
j = 1
k = 1
l = 1
m = 1
n = 1
Do While j <= UBound(c4)
Do While k <= UBound(c5)
Do While l <= UBound(c6)
Do While m <= UBound(c8)
out1(n, 1) = c1(j, 1)
out1(n, 2) = c2(k, 1)
out1(n, 3) = c3(l, 1)
out1(n, 4) = c8(m, 1)
n = n + 1
m = m + 1
Loop
m = m
l = l + 1
Loop
l = 1
k = k + 1
Loop
k = 1
j = j + 1
Loop
out_1.Value = out1
out_2.Value = out2
End Sub
debug.printing all your UBound(cN)'s to see what the values are.