I have a code below that runs all possible combinations for as many columns as i have in sheet 1.
the problem is that if i have a certain number of cells that would create more than 1,048,000 (excel line limit) different permutations, then the code will stop even though there could be more permutations to calculate.
Can anyone modify this code to continue over to column B and so on so that all possible permutations can be created?
thank you.
the problem is that if i have a certain number of cells that would create more than 1,048,000 (excel line limit) different permutations, then the code will stop even though there could be more permutations to calculate.
Can anyone modify this code to continue over to column B and so on so that all possible permutations can be created?
thank you.
Code:
Sub Permute()
Dim ix(100, 1) As Long, rc As Long, m As Long, br As Long, md As Variant, i As Long, r As Long
Dim str1 As String
rc = Cells(1, Columns.Count).End(xlToLeft).Column
m = 0
For i = 1 To rc
br = Cells(Rows.Count, i).End(xlUp).Row
If br > m Then m = br
ix(i, 0) = br
ix(i, 1) = 1
Next i
md = Range(Cells(1, 1), Cells(m, rc)).Value
r = 0
Incr:
str1 = ""
For i = 1 To rc
str1 = str1 & md(ix(i, 1), i)
Next i
r = r + 1
Sheets("Sheet2").Cells(r, "A") = str1
For i = rc To 1 Step -1
ix(i, 1) = ix(i, 1) + 1
If ix(i, 1) <= ix(i, 0) Then Exit For
ix(i, 1) = 1
Next i
If i > 0 Then GoTo Incr:
End Sub
Last edited: