View Single Post
  #3   Report Post  
HL8 HL8 is offline
Junior Member
 
Posts: 2
Default

This worked perfectly. Thanks for the help!


Quote:
Originally Posted by joeu2004[_2_] View Post
"HL8" wrote:
Sub Permutations_2()
Dim rRng As Range
Dim lRow As Long, j As Long, k As Long
Set rRng = Range("A1", Range("A1").End(xlDown)) ' The set of values
For j = 1 To rRng.Count
For k = 1 To rRng.Count
If j < k Then
lRow = lRow + 1
Range("C" & lRow) = Range("a" & j)
Range("D" & lRow) = Range("a" & k)
End If
Next k
Next j
End Sub

Any ideas on how to eliminate the duplicates -
either in the macro or in an additional step?


For j = 1 to rRng.Count-1
For k = j + 1 to rRng.Count
lRow = lRow + 1
Range("C" & lRow) = Range("a" & j)
Range("D" & lRow) = Range("a" & k)
Next
Next

More efficient:

Dim v As Variant
For j = 1 to rRng.Count-1
v = Range("a" & j)
For k = j + 1 to rRng.Count
lRow = lRow + 1
Range("C" & lRow) = v
Range("D" & lRow) = Range("a" & k)
Next
Next