I want to get all possible combinations of certain values present in a column range and print them in an excel sheet:
Please note that the order of combination does not matter i.e AB=BA
Here is an example of data in column1 for which combinations are to be found:
F1
F2
F3
F4
The possible combinations of these are :
F1F2
F1F3
F1F4
F2F3
F2F4
F3F4
F1F2F3
F1F2F4
F1F3F4
F2F3F4
F1F2F3F4
This is my first Stack Overflow answer:
This might not be the most elegant approach, but it works. First eliminate any repetitions in the data. My inclination is to use a VBScript dictionary for that -- but you can do it in pure VBA like this. If you have n distinct items -- count from 0 to 2^n -1 in base 2, each of which corresponds to a combination (subset). You seem to want to throw out subsets of size less than 2. I wrote a function which does this, as well as a sub to test it with. The sub assumes that the data starts in A1 and is contiguous. It prints the results in column B: