Попробуйте этот код, пожалуйста. Я изначально пытался ответить только на ваш вопрос. Теперь я также немного адаптировал ваш код. Пожалуйста, попробуйте для диапазонов, которые вы показали нам в вопросе. Если вы увеличите их, код должен быть адаптирован (не очень сложен), чтобы также использовать другие массивы и, возможно, удалять содержимое массивов в некоторых файлах .csv. Пожалуйста, проверьте это как есть и подтвердите, что это то, чего вы хотели достичь.
Sub combinations()
Dim c1() As Variant, c2() As Variant, c3() As Variant, c4() As Variant
Dim c5() As Variant, c6() As Variant, c7() As Variant, c8() As Variant
Dim j As Long, k As Long, l As Long, m As Long, n As Long
Dim o As Long, p As Long, q As Long, r As Long
Dim col1 As Range, col2 As Range, col3 As Range, col4 As Range
Dim col5 As Range, col6 As Range, col7 As Range, col8 As Range
Dim out1 As Range, out() As Variant
Set col1 = Range("A1:A6"): Set col2 = Range("B1:B6")
Set col3 = Range("C1:C6"): Set col4 = Range("D1:D6")
Set col5 = Range("E1:E6"): Set col6 = Range("F1:F6")
Set col7 = Range("G1:G6"): Set col8 = Range("H1:H6")
c1 = col1: c2 = col2: c3 = col3: c4 = col4
c5 = col5: c6 = col6: c7 = col7: c8 = col8
'___________________________________________________________________________
Dim out2 As Range, outBis As Variant, acceptR As Double, boolNext As Double
Const maxR As Long = 1048574
acceptR = UBound(c1) * UBound(c2) * UBound(c3) * UBound(c4) * UBound(c5) * UBound(c6) * UBound(c7) * UBound(c8)
If acceptR > maxR Then
Set out1 = Range("J2", Range("Q2").Offset(maxR))
Set out2 = Range("T2", Range("AA2").Offset(acceptR - maxR))
out = out1.value
outBis = out2.value ' only for easy array dimensstoning
Else
Set out1 = Range("J2", Range("Q2").Offset(acceptR))
out = out1.value
End If
'_______________________________________________________________________________
j = 1: k = 1: l = 1: m = 1: n = 1: o = 1: p = 1: q = 1: r = 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)
If Not boolNext Then
out(r, 1) = c1(j, 1)
out(r, 2) = c2(k, 1)
out(r, 3) = c3(l, 1)
out(r, 4) = c4(m, 1)
out(r, 5) = c5(n, 1)
out(r, 6) = c6(o, 1)
out(r, 7) = c7(p, 1)
out(r, 8) = c8(q, 1)
r = r + 1
q = q + 1
If r = maxR Then boolNext = True : r = 1
Else
outBis(r, 1) = c1(j, 1)
outBis(r, 2) = c2(k, 1)
outBis(r, 3) = c3(l, 1)
outBis(r, 4) = c4(m, 1)
outBis(r, 5) = c5(n, 1)
outBis(r, 6) = c6(o, 1)
outBis(r, 7) = c7(p, 1)
outBis(r, 8) = c8(q, 1)
r = r + 1
q = q + 1
End If
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
If UBound(outBis) > 1 Then out2.value = outBis
End Sub