Is there a way to create a macro in excel to generate all possible combinations (Cartesian product) of a number of sets (more than 8), each containing a dynamic number of words (up to 60 words).
eg. if I have 4 sets as below:
- Set 1: A1
- Set 2: B1, B2, B3, B4
- Set 3: C1, C2
- Set 4: D1, D2
It should create 16 combinations: (A1 B1 C1 D1), (A1 B1 C2 D1), (A1 B1 C1 D2), (A1 B1 C2 D2), (A1 B2 C1 D1), (A1 B2 C2 D1), (A1, B2 C1 D2), (A1 B2 C2 D2), (A1 B3 C1 D1), (A1 B3 C2 D1), (A1 B3 C1 D2), (A1 B3 C2 D2), (A1 B4 C1 D1), (A1 B4 C2 D1), (A1 B4 C1 D2), (A1 B4 C2 D2) -Please see the picture
The above example is easy to make manyally. But for the below one, it is supposed to create 3456 combinations
- Set 1 A1
- Set 2 B1 B2 B3 B4
- Set 3 C1 C2
- Set 4 D1 D2 D3 D4
- Set 5 E1 E2
- Set 6 F1 F2 F3 F4 F5 F6
- Set 7 G1 G2 G3
- Set 8 H1 H2 H3
Any idea how to do that for dynamic number of sets with dynamic number of words? Thanks A Lot.