Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / April 2008

Tip: Looking for answers? Try searching our database.

'combine' question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Christopher - 05 Apr 2008 23:50 GMT
Hello all,

Perhaps someone can help me with the following question.

The function 'combine' tells me that if 12 objects are divided in to groups
of 4 items there are a possible 495 combinations.
I want to visualize those 495 combinations.
I have not been able to do so after several atempts to write some code in
VBA. I'm always missing some.

Any help?

Thanks,
Christopher
Jim Cone - 06 Apr 2008 00:04 GMT
Enter 12 in the first Input box, enter 4 in the second Input box.
Signature

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

'--
'Code by John Warren March 21, 2001
'Modified by Jim Cone April 06, 2006
'Calls Comb2 sub.
'Creates the list in a single column.
'Select the top cell of the column then run code.
Sub Combinations()
Dim n As Variant
Dim m As Variant
ReStart:
n = InputBox("Number of items?", "Combinations")
If Len(n) = 0 Then Exit Sub
m = InputBox("Taken how many at a time?", "Combinations")
If Len(m) = 0 Then GoTo ReStart

Application.ScreenUpdating = False
Comb2 n, m, 1, vbNullString, ActiveCell
Application.ScreenUpdating = True
End Sub

'Generate combinations of integers k..n taken m at a time, recursively
'John Warren March 21, 2001
'Modified by Jim Cone April 06, 2006
Sub Comb2(ByVal n As Integer, ByVal m As Integer, ByVal k As Integer, _
         ByVal s As String, ByRef rng As Excel.Range)
If m > n - k + 1 Then Exit Sub
If m = 0 Then
  rng.Value = RTrim$(s)
  Set rng = rng(2, 1)
  Exit Sub
End If
Comb2 n, m - 1, k + 1, s & k & " ", rng
Comb2 n, m, k + 1, s, rng
End Sub
'----------

"Christopher"
wrote in message
Hello all,
Perhaps someone can help me with the following question.
The function 'combine' tells me that if 12 objects are divided in to groups
of 4 items there are a possible 495 combinations.
I want to visualize those 495 combinations.
I have not been able to do so after several atempts to write some code in
VBA. I'm always missing some.
Any help?
Thanks,
Christopher

Max - 06 Apr 2008 00:06 GMT
One play is to use Myrna Larson's power subroutine
to generate the combinations ..

Take away this implemented sample from my archives:
http://www.savefile.com/files/518493
MyrnaLarson_Combination_Permutation.xls
(full details inside, ready to run)

In the sample file,
In Sheet1,
1. Enter the letter C or P in A1
(C = combinations, P = permutations), ie enter: C
2. Enter the number of items involved per combo in A2, ie enter: 3
3. Enter/List the 6 items in A3 down, ie list in A3:A8  :1, 2, ... 6
4. Select A1 (this cell selection is required),
then click the button ListPermutations to run the sub ListPermutations
5. The results will be written to a new sheet (just to the left),
and appear like below, in a zig-zag manner* until all combos are exhausted:
*if it exceeds the rows limit of 65536 in xl97 to xl2003

1, 2, 3
1, 2, 4
1, 2, 5
1, 2, 6
...
4, 5, 6

Go easy when you *ramp* up the generation ...
eg a "Pick 6 out of 45" run works out to a staggering:
=COMBIN(45,6) = 8,145,060 combinations
so almost half** an entire sheet would be populated

**A single sheet in xl97 to xl2003 houses:
=65536 rows x 256 cols = 16,777,216 cells

The sub would certainly need time to complete generation
Signature

Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---

> Hello all,
>
[quoted text clipped - 11 lines]
> Thanks,
> Christopher
Paul Hyett - 06 Apr 2008 08:24 GMT
>One play is to use Myrna Larson's power subroutine
>to generate the combinations ..
>
>Take away this implemented sample from my archives:
>http://www.savefile.com/files/518493
>MyrnaLarson_Combination_Permutation.xls

What a useful little spreadsheet - thanks for recommending it!
Signature

Paul Hyett, Cheltenham (change 'invalid83261' to 'blueyonder' to email me)

Max - 06 Apr 2008 08:54 GMT
welcome, Paul
Signature

Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---

> What a useful little spreadsheet - thanks for recommending it!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.