This macro should take two list and create every combination of the two list in a third column
a1 b1
a2 b2
should give the following list (not sure what order)
a1 b1
a2 b1
a2 b1
a2 b2
b1 a1
b1 a2
b2 a1
b2 a2
The excel macro gives a Run-time error '6" Overflow on this line "Set rngOutB = Range("D" & (rngL1.Rows.Count * rngL2.Rows.Count * 2))".
Any suggestions on how to fix it?
This is the macro:
Sub CreatePermutations()
Dim rngL1 As Range
Dim rngL2 As Range
Dim rngA As Range
Dim rngB As Range
Dim rngOutA As Range
Dim rngOutB As Range
Set rngL1 = Range("A1", Range("A1").End(xlDown))
Set rngL2 = Range("B1", Range("B1").End(xlDown))
Set rngOutA = Range("D1")
Set rngOutB = Range("D" & (rngL1.Rows.Count * rngL2.Rows.Count * 2))
For Each rngA In rngL1.Cells
For Each rngB In rngL2.Cells
rngOutA = rngA.Value * " " & rngB.Value
rngOutB = rngB.Value & " " & rngA.Value
Set rngOutA = rngOutA.Offset(1, 0)
Set rngOutB = rngOutB.Offset(-1, 0)
Next
Next
End Sub
a1 b1
a2 b2
should give the following list (not sure what order)
a1 b1
a2 b1
a2 b1
a2 b2
b1 a1
b1 a2
b2 a1
b2 a2
The excel macro gives a Run-time error '6" Overflow on this line "Set rngOutB = Range("D" & (rngL1.Rows.Count * rngL2.Rows.Count * 2))".
Any suggestions on how to fix it?
This is the macro:
Sub CreatePermutations()
Dim rngL1 As Range
Dim rngL2 As Range
Dim rngA As Range
Dim rngB As Range
Dim rngOutA As Range
Dim rngOutB As Range
Set rngL1 = Range("A1", Range("A1").End(xlDown))
Set rngL2 = Range("B1", Range("B1").End(xlDown))
Set rngOutA = Range("D1")
Set rngOutB = Range("D" & (rngL1.Rows.Count * rngL2.Rows.Count * 2))
For Each rngA In rngL1.Cells
For Each rngB In rngL2.Cells
rngOutA = rngA.Value * " " & rngB.Value
rngOutB = rngB.Value & " " & rngA.Value
Set rngOutA = rngOutA.Offset(1, 0)
Set rngOutB = rngOutB.Offset(-1, 0)
Next
Next
End Sub