M
Maxi
Sub Combinations()
Dim n As Integer, m As Integer
numcomb = 0
n = InputBox("Number of items?", "Combinations")
m = InputBox("Taken how many at a time?", "Combinations")
Comb2 n, m, 1, "'"
End Sub
'Generate combinations of integers k..n taken m at a time, recursively
Sub Comb2(ByVal n As Integer, ByVal m As Integer, _
ByVal k As Integer, ByVal s As String)
If m > n - k + 1 Then Exit Sub
If m = 0 Then
ActiveCell = s
ActiveCell.Offset(1, 0).Select
Exit Sub
End If
Comb2 n, m - 1, k + 1, s & k & " "
Comb2 n, m, k + 1, s
End Sub
I am referring to the above code written by Tom Ogilvy and trying to
manipulate it to meet my requirement but I did not get any success
inspite of trying so many times.
Before I explain what exactly I want, I would like to tell you guys
that I have the following data in A1:T1
3,4,6,10,11,13,18,21,30,32,33,35,46,53,60,67,69,74,77,78
Manipulation required:
----------------------
1. Tom's code gives the result as a string separated by a SPACE and I
want it in integers in different cells.
2. Tom's code gives flexibility to the user to choose "Number of items"
and "Taken how many times". In my case items will always be 20 (data in
range A1:T1) and "Taken how many times" will depend on user input
(Min:2 and Max:10)
3. For instance, if n=20 (it will always be 20) and m=5 (user input)
then Tom's code will generate the first combination as 1 2 3 4 5
whereas the result what I want is 3 4 6 10 11 (in different cells)
I will use Tom's combination 1 2 3 4 5 as offsets to find out my
combination 3 4 6 10 11 which is cells(1,1).value cells(1,2).value
cells(1,3).value cells(1,4).value cells(1,5).value given in the range
A1:T1
Original problem:
--------------------
Actually I have posted a different question in the link given below for
which I am not getting any replies and therefore I have decided to work
on that myself but I need a start as am confused how and where to start
with.
http://groups.google.com/group/micr...read/thread/4568c79732db4eba/624a5d06ae786d57
If anybody can clear my doubts and change the above code according to
my requirement then probably I can start working on my original post. I
am not sure whether I will be able to do it completely but atleast I
can try.
It would be great if Tom or any of the pros in this group can have a
look at my original post and suggest a logic on how to do it.
http://groups.google.com/group/micr...read/thread/4568c79732db4eba/624a5d06ae786d57
Many Thanks
Maxi
Dim n As Integer, m As Integer
numcomb = 0
n = InputBox("Number of items?", "Combinations")
m = InputBox("Taken how many at a time?", "Combinations")
Comb2 n, m, 1, "'"
End Sub
'Generate combinations of integers k..n taken m at a time, recursively
Sub Comb2(ByVal n As Integer, ByVal m As Integer, _
ByVal k As Integer, ByVal s As String)
If m > n - k + 1 Then Exit Sub
If m = 0 Then
ActiveCell = s
ActiveCell.Offset(1, 0).Select
Exit Sub
End If
Comb2 n, m - 1, k + 1, s & k & " "
Comb2 n, m, k + 1, s
End Sub
I am referring to the above code written by Tom Ogilvy and trying to
manipulate it to meet my requirement but I did not get any success
inspite of trying so many times.
Before I explain what exactly I want, I would like to tell you guys
that I have the following data in A1:T1
3,4,6,10,11,13,18,21,30,32,33,35,46,53,60,67,69,74,77,78
Manipulation required:
----------------------
1. Tom's code gives the result as a string separated by a SPACE and I
want it in integers in different cells.
2. Tom's code gives flexibility to the user to choose "Number of items"
and "Taken how many times". In my case items will always be 20 (data in
range A1:T1) and "Taken how many times" will depend on user input
(Min:2 and Max:10)
3. For instance, if n=20 (it will always be 20) and m=5 (user input)
then Tom's code will generate the first combination as 1 2 3 4 5
whereas the result what I want is 3 4 6 10 11 (in different cells)
I will use Tom's combination 1 2 3 4 5 as offsets to find out my
combination 3 4 6 10 11 which is cells(1,1).value cells(1,2).value
cells(1,3).value cells(1,4).value cells(1,5).value given in the range
A1:T1
Original problem:
--------------------
Actually I have posted a different question in the link given below for
which I am not getting any replies and therefore I have decided to work
on that myself but I need a start as am confused how and where to start
with.
http://groups.google.com/group/micr...read/thread/4568c79732db4eba/624a5d06ae786d57
If anybody can clear my doubts and change the above code according to
my requirement then probably I can start working on my original post. I
am not sure whether I will be able to do it completely but atleast I
can try.
It would be great if Tom or any of the pros in this group can have a
look at my original post and suggest a logic on how to do it.
http://groups.google.com/group/micr...read/thread/4568c79732db4eba/624a5d06ae786d57
Many Thanks
Maxi