Excel create table with all combinations
Let's assume I have 3 columns with labels
- A B C D
- a b c d e
- 1 2 3 4 5 6 7 8 9 10
Is there a quick and easy way to create an empty table with all permutations? i.e.
- A - a - 1
- A - a - 2
- ....
- D - e - 10
Solution 1:
Running this short macro:
Sub marine()
Dim i As Long, j As Long, k As Long, N As Long
N = 1
For i = 1 To 4
For j = 1 To 5
For k = 1 To 10
Cells(N, 4) = Cells(i, 1) & "-" & Cells(j, 2) & "-" & Cells(k, 3)
N = N + 1
Next k
Next j
Next i
End Sub
will produce a column of the desired 200 combinations:
Solution 2:
You can do this with a formula:
=IFERROR(INDEX($A$1:$A$4,INT((ROW(1:1)-1)/((COUNTA(B:B)*(COUNTA(C:C)))))+1)&" - "&INDEX(B:B,MOD(INT((ROW(1:1)-1)/COUNTA(C:C)),COUNTA(B:B))+1)&" - "&INDEX(C:C,MOD((ROW(1:1)-1),COUNTA(C:C))+1),"")