S.H.A.D.O.
Well-known Member
- Joined
- Sep 6, 2005
- Messages
- 1,915
The code below was written by pgc01 which I found while doing a search on this forum.
What I would like is for once the output gets to say 10,000 rows it stops and moves EIGHT columns to the right and then continues, and it keeps doing this until the code finishes processing please.
Here is the code:
Thanks in advance.
What I would like is for once the output gets to say 10,000 rows it stops and moves EIGHT columns to the right and then continues, and it keeps doing this until the code finishes processing please.
Here is the code:
Code:
Sub Combinations()
Dim rRng As Range, p
Dim vElements, lRow As Long, vResult As Variant, vResults As Variant
vElements = VBA.Array("01", "02", "03", "04", "05", "06", "07", "08", "09", _
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", _
"20", "21", "22", "23", "24")
p = 6
ReDim vResult(0 To p - 1)
ReDim vResults(1 To Application.WorksheetFunction.Combin(UBound(vElements) + 1, p), 1 To 1)
Call CombinationsNP(vElements, CInt(p), vResult, vResults, lRow, 0, 0)
' The combinations are in vResults. For ex. write it to the WorkSheet.
Range("A1").Resize(UBound(vResults)) = vResults
End Sub
Sub CombinationsNP(vElements As Variant, p As Integer, vResult As Variant, vResults, lRow As Long, _
iElement As Integer, iIndex As Integer)
Dim i As Integer
For i = iElement To UBound(vElements)
vResult(iIndex) = vElements(i)
If iIndex = p - 1 Then
lRow = lRow + 1
vResults(lRow, 1) = Join(vResult, ",")
Else
Call CombinationsNP(vElements, p, vResult, vResults, lRow, i + 1, iIndex + 1)
End If
Next i
End Sub
Thanks in advance.