LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Tom Ogilvy's VBA code

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/micro...4a5d06ae786d57

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/micro...4a5d06ae786d57

Many Thanks
Maxi

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Code to conditional format all black after date specified in code? wx4usa Excel Discussion (Misc queries) 3 December 26th 08 07:06 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
Create a newworksheet with VBA code and put VBA code in the new worksheet module ceshelman Excel Programming 4 June 15th 05 04:37 PM
stubborn Excel crash when editing code with code, one solution Brian Murphy Excel Programming 0 February 20th 05 05:56 AM


All times are GMT +1. The time now is 07:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"