View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default All combinations

It's too late now (Amsterdam 03:00 at night)

i have some code in the works but need to finalize and tune tomorrow.

How large are the combinations you'll require?

is it ok to exit on a max of 65000 combinations ?
or should it continue until memory is maxed out?
or should it write to an external file?

as you may realize the quantities can be stupendous..
...

i'll be back :)


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Seokho Moon" wrote:

Hi, all
I want to return all possible combinations using the numbers of a
specified range.
For example, if I specify a certain range, whose value is {1,2;3,4},
and input 2, the hopeful result is {1,2;1,3;1,4;2,3;2,4;3,4}.
What I want is sub procedure with two arguments(range, number of
selection).

I know how can do this only if the number of selection is fixed.

Sub AllCombi()
Dim rngX As Range
Dim intX As Integer
Dim intY As Integer
Dim intZ As Integer
Dim intA As Integer
Set rngX = Application.InputBox("Specify the range", Type:=8)
intX = rngX.Cells.Count
intA = 1
For intY = 1 To intX - 1
For intZ = intY + 1 To intX
Cells(intA, 1) = intY
Cells(intA, 2) = intZ
intA = intA + 1
Next intZ
Next intY
End Sub

When the number of looping sentence is a variable, how can I solve it?
That's the point.

Any advice would be much appreciated.