Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Tom,
You had given me the below code. I need a little change. Please help me out one more time. Now I don't need an input box for m [ m = InputBox("Taken how many at a time?", "Combinations") ]. It will be 10 (fixed). There is a difference in the range as well. I have the following numbers in the range W1:AK19 (please do not change the range let it be in W1:AK19) 4,9,10,21,35,47,64,72,74,75 4,9,10,21,33,41,47,57,60,72,74 3,4,10,11,21,32,33,35,60,69,74 3,4,7,10,21,33,37,47,57,69,75 4,7,32,37,47,57,60,64,72,74 3,7,10,11,35,47,57,60,64,66,67,72,73,79,80 4,7,9,10,11,32,35,41,69,74 3,4,10,21,32,37,47,64,69,72,75,77 3,7,11,33,35,37,41,47,64,75 4,6,9,10,15,21,31,47,72,74 6,9,13,21,22,31,49,52,63,64,75 9,10,12,21,22,47,49,52,64,72 4,6,9,12,15,35,47,56,63,72 6,9,12,15,21,31,47,64,74,75 6,9,10,13,21,49,52,63,72,74,75,79,80 4,6,13,15,35,56,63,64,74,75 13,15,21,35,47,49,56,63,72,75 4,15,42,45,47,57,60,68,72,74 10,16,28,47,51,52,55,64,71,72,74,75,76,77 I want to create combinations of the first series W1:AF1 =combin(10,1) then below that I want to create combinations for the second series W1:AG1 =combin(11,10) and go on listing combinations one below the other for all the 19 series. Total combinations should be 4411 I do not want to list these total 4411 combinations on a worksheet, I want to send it to an array either and towards the end of the code, just before 'End Sub" I need an input box asking me which combination to display. If I type 34, it should display 34th element of the array in the range AM1:AV1 Your code: Sub Combinations() Dim n As Integer, m As Integer Dim v As Variant, rng As Range numcomb = 0 Set rng = Range("A1:T1") 'Set rng = rng.Resize(1, 5) v = Application.Transpose(Application _ .Transpose(rng)) n = UBound(v, 1) m = InputBox("Taken how many at a time?", "Combinations") If Application.Combin(n, m) 64530 Then MsgBox "Too many to write out, quitting" Exit Sub End If Range("A3").Select Comb2 n, m, 1, "'", v 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, v As Variant) Dim v1 As Variant If m n - k + 1 Then Exit Sub If m = 0 Then 'Debug.Print "-" & s & "<-" v1 = Split(Replace(Trim(s), "'", ""), " ") For i = LBound(v1) To UBound(v1) ActiveCell.Offset(0, i) = v(v1(i)) Next ActiveCell.Offset(1, 0).Select Exit Sub End If Comb2 n, m - 1, k + 1, s & k & " ", v Comb2 n, m, k + 1, s, v End Sub Thanx Maxi |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Tom Ogilvy | Excel Worksheet Functions | |||
Tom Ogilvy - More help please | Excel Programming | |||
To Tom Ogilvy | Excel Programming | |||
Thank You Tom Ogilvy | Excel Worksheet Functions | |||
Tom Ogilvy | Excel Programming |