combination lists

  • Thread starter Thread starter jim
  • Start date Start date
J

jim

I've got 7 categories and each have two possible values, a and b. I'd
like an excel macro to list all the possible combinations in an array
for all the categories. I know there are 128, but I don't know how to
create and list all combinations. Anybody know how?
 
Does this do what you want?

Sub Combi()
Dim i As Integer

For i = 1 To 128
Cells(i, 1) = ab(i)
Next i

End Sub

Function ab(P As Integer) As String
Dim n As Integer
ab = ""
For n = 0 To 6
ab = ab & IIf(P And 2 ^ n, "a", "b")
Next n
End Function
 
Hello Jim,

Based on the following assumptions, I don't know how you calculated
128.

Assuming you have 7 categories (sets) and 2 values (size) with no
repeating values and position matters (AB is different from BA) the
number of possible outcomes is given by...

7! / (7 - 2)! = 7 x 6 = 42

Did you have something different in mind for arranging the data?

Sincerely,
Leith Ross
 
Back
Top