=COMBIN(26,3)

B

Bigcol

I can use this to give me the number of possible combinations, in this
case 3 from 26, is there anyway I can produced a table of possible
results if we assume 1=a, 2=b 3=c etc. I am new to excel and want to
look at combinations and their results.
 
B

Bigcol

I can use this to give me the number of possible combinations, in this
case 3 from 26, is there anyway I can produced a table of possible
results if we assume 1=a, 2=b 3=c etc.  I am new to excel and want to
look at combinations and their results.

I came across this but dont know how to use it

Sub test()
Dim r As Long
n = Range("B1")
c = Range("B2")


For r = 1 To c
i = Application.WorksheetFunction.Combin(n, r)
Cells(5 + r, 1) = i
Next r
End Sub
 
J

joeu2004

I came across this but dont know how to use it

That VBA macro does not answer your question as I understand it. What
it does....

Given 26 in B1 and 3 in B2, for example, the macro produces a table
starting in A6 of effectively =COMBIN(B1,1), =COMBIN(B1,2),
=COMBIN(B1,3), etc up to =COMBIN(B1,B2).

In other words, it simply computes the number of combinations. It
does not produce the combinations.


----- original message -----
 
J

joeu2004

I can use this to give me the number of possible combinations, in this
case 3 from 26, is there anyway I can produced a table of possible
results if we assume 1=a, 2=b 3=c etc.  I am new to excel and want to
look at combinations and their results.

As I understand it, you would like to see the combinations of "A"
through "Z" taken 3 at a time; for example, ABC, ABD,..., ABZ, ACD,
ACE, etc.

Note: COMBIN counts the number of sets of 3-letter combinations; so
ABC, ACB etc are counted as one. I wonder if you want PERMUT, which
counts the number of permutations of each 3-letter set; so ABC, ACB,
BAC, BCA, CAB and CBA each count. On the other hand, I wonder if you
to count arrangements like AAA, AAB, AAC etc (permutations with
replacement). That is counted by the formula 26^3.

In any case, to answer your question: "Is there any way I can
produced a table of possible results?".

There is (almost) always "a way". The question is: Is it feasible to
implement and execute?

In part, that depends on the COMBIN (or PERMUT or n^c) parameters;
that is, the number of rows produced by all of the arrangements.

You neglect to mention what version of Excel you are using. But for
any version, the number of combinations or permutations with or
without replaces might be too large to consider feasible.

In the case of 26 letters taken 3 at a time, all three types of
arrangements are feasible: COMBIN(26,3) is 2600; PERMUT(26,3) is
15,600; and 26^3 is 17,576.

See the following VBA macros. To use VBA macros (at least in Excel
2003):

1. In Excel, open or select a worksheet.
2. Press alt+F11 to open a VBA window.
3. In VBA, click Insert > Module, or select an existing module. This
should open a VBA editing pane.
4. Copy the macros below (highlight text and press ctrl+C), and paste
into the VBA editing pane (ctrl+V).
5. Edit the macros as needed. See the comment after the Sub line.
6. In Excel, select the first cell where you can the column of
arrangements.
7. Press alt+F8, and run the desired macro.

PS: For broader participation, you might want to post future
inquiries using the MS Answers Forums at
http://social.answers.microsoft.com/Forums/en-US/category/officeexcel.
It's not that I like that forum. It's just that MS has ceased to
support the Usenet newsgroups. Hence, participation here is limited
to the sites that share a common newsgroup mirror, which is no longer
centralized at MS.


Macros....

Option Explicit

Sub doPermut_withReplacement() '26^3 arrangements
'Change cA as needed
Const cA As Long = 65 'A=65, a=97
Dim i As Long, j As Long, k As Long, n As Long
Dim ci As String * 1, cj As String * 1, ck As String * 1
Dim r As Range
Application.ScreenUpdating = False
Set r = Selection: n = 0
For i = 0 To 25
ci = Chr(i + cA)
For j = 0 To 25
cj = Chr(j + cA)
For k = 0 To 25
ck = Chr(k + cA)
r.Offset(n) = ci & cj & ck
n = n + 1
Next k: Next j: Next i
Application.ScreenUpdating = True
MsgBox n & " in " & Selection.Resize(n).Address
End Sub

Sub doPermut_withoutReplacement() 'PERMUT(26,3) arrangements
'Change cA as needed
Const cA As Long = 65 'A=65, a=97
Dim i As Long, j As Long, k As Long, n As Long
Dim ci As String * 1, cj As String * 1, ck As String * 1
Dim r As Range
Application.ScreenUpdating = False
Set r = Selection: n = 0
For i = 0 To 25
ci = Chr(i + cA)
For j = 0 To 25
cj = Chr(j + cA)
If ci <> cj Then
For k = 0 To 25
ck = Chr(k + cA)
If ci <> ck And cj <> ck Then
r.Offset(n) = ci & cj & ck
n = n + 1
End If
Next k
End If
Next j: Next i
Application.ScreenUpdating = True
MsgBox n & " in " & Selection.Resize(n).Address
End Sub

Sub doCombin() 'COMBIN(26,3) arrangements
'Change cA as needed
Const cA As Long = 65 'A=65, a=97
Dim i As Long, j As Long, k As Long, n As Long
Dim ci As String * 1, cj As String * 1, ck As String * 1
Dim r As Range
Application.ScreenUpdating = False
Set r = Selection: n = 0
For i = 0 To 23
ci = Chr(i + cA)
For j = i + 1 To 24
cj = Chr(j + cA)
For k = j + 1 To 25
ck = Chr(k + cA)
r.Offset(n) = ci & cj & ck
n = n + 1
Next k: Next j: Next i
Application.ScreenUpdating = True
MsgBox n & " in " & Selection.Resize(n).Address
End Sub
 
J

joeu2004

PS....

Sub doPermut_withoutReplacement()  'PERMUT(26,3) arrangements [....]
For i = 0 To 25
   ci = Chr(i + cA)
   For j = 0 To 25
      cj = Chr(j + cA)
      If ci <> cj Then
         For k = 0 To 25
            ck = Chr(k + cA)
            If ci <> ck And cj <> ck Then
               r.Offset(n) = ci & cj & ck
               n = n + 1
            End If
         Next k
      End If
Next j: Next i

FYI, we might think the following alternative is more efficient:

For i = 0 To 23
ci = Chr(i + cA)
For j = i + 1 To 24
cj = Chr(j + cA)
For k = j + 1 To 25
ck = Chr(k + cA)
r.Offset(n) = ci & cj & ck
r.Offset(n + 1) = ci & ck & cj
r.Offset(n + 2) = cj & ci & ck
r.Offset(n + 3) = cj & ck & ci
r.Offset(n + 4) = ck & ci & cj
r.Offset(n + 5) = ck & cj & ci
n = n + 6
Next k: Next j: Next i

That loops 2600 times instead of 17,576 times.

However, the execution time is about the same. Presumably the
execution time to assign to r.Offset far outweighs the execution time
for looping and conditional testing.

Besides, the first algorithm generates strings in a "nicer" order.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top