View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] sandip.dhamapurkar@gmail.com is offline
external usenet poster
 
Posts: 29
Default Count & List Combinations

I was searching articles on this and I found one where John W.
Vinson[MVP] says "combinations and permutations are duck soup to
Access. You don't need any code AT ALL. All you need is a cartesian
join Query!" I also found articles by Excel and Access MVPs like Tom
Ellison, Bernie Deitrick, Tom Ogilvy and few more.

Following is a code taken from Bernie's article and manipulated
according to my needs. Can anyone check if it is correct?

Sub Comb()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Integer
Dim n As Integer

For i = 2 To Range("A65536").End(xlUp).Row
For j = 2 To Range("B65536").End(xlUp).Row
For k = 2 To Range("C65536").End(xlUp).Row
For l = 2 To Range("D65536").End(xlUp).Row
For m = 2 To Range("E65536").End(xlUp).Row
For n = 2 To Range("F65536").End(xlUp).Row

Range("H65536").End(xlUp)(2).Value = Cells(i, 1).Value & "-" & _
Cells(j, 2).Value & "-" & Cells(k, 3).Value & "-" & _
Cells(l, 4).Value & "-" & Cells(m, 5).Value & "-" & Cells(n, 6).Value
Next n
Next m
Next l
Next k
Next j
Next i

End Sub

It is is correct so far, I need to make a small change but not sure how
to do it. Per my explanation, 2,2,3,52,58,61 should also be a valid
combination but it should not as the first and second number is same
even though the fall in N1 and N2. This becomes the second criteria,
all the six numbers in a combiation should be unique. How can I modify
the above code to take care of this criteria?

Also requesting John W. Vinson[MVP] to let me know if this can be done
in access using a join query.