Global ptr As Long, icomb As Long, iLoop
Public MyResult, a(), arr3(), Arr_Exclusives, Aux(), MyChoices, iPlayers, WB150 As Worksheet, TB As Shape, bTekstbox, bUF1
Sub NewData()
With Range("A2:A25")
.Value = Range("N1:N47").Value
.Sort .Range("A1"), Header:=xlNo
End With
End Sub
Sub All_Combinations()
t = Timer
MyChoices = Range("A2:A25")
MyCombinations_L 24, 5
ReDim Preserve arr3(1 To UBound(arr3), 1 To 6)
For i = 1 To UBound(arr3)
For j = 1 To Len(arr3(i, 1))
arr3(i, 1 + j) = MyChoices(Asc(Mid(arr3(i, 1), j, 1)) - 64, 1)
Next
Next
Range("B2").Resize(UBound(arr3), UBound(arr3, 2)).Value = arr3
MsgBox Timer - t
End Sub
Sub MyCombinations_L(Aantal, gekozen)
Dim L(), Arr(), Arr2(), iCombinations As Long, Last(), Actual()
x = Evaluate("=char(row(65:" & 65 + Aantal - 1 & "))")
L = Application.Transpose(x)
t = Timer
iCombinations = WorksheetFunction.Combin(Aantal, gekozen) 'aantal combinaties
ReDim Actual(1 To gekozen) 'voorbereiden array
ReDim Arr2(iCombinations - 1) 'voorbereiden 2e array, igv. je de waarden wil zien
ReDim arr3(1 To iCombinations, 1 To 1)
For r = 1 To iCombinations 'alle combinaties doorlopen
If r = 1 Then '1e keer = alles op 1,2,3, .... zetten
For k = 1 To gekozen: Actual(k) = k: Next
Else
vorig = Actual
Actual(gekozen) = vorig(gekozen) + 1
If Actual(gekozen) > Aantal Then 'laatste voorbij target !
For k = gekozen - 1 To 1 Step -1 'voorgaande kolommen aflopen
If Actual(k) < Aantal - (gekozen - k) Then 'tot aan die kolom die nog 1 mag opgehoogd worden
Actual(k) = Actual(k) + 1 'die kolom 1 ophogen
For k1 = k + 1 To gekozen 'alle volgende kolommen
Actual(k1) = Actual(k1 - 1) + 1 'gelijk aan de vorige kolom +1
Next
Exit For 'wip uit de loop
End If
Next
End If
End If
For k = 1 To gekozen: Arr2(r - 1) = Arr2(r - 1) & L(Actual(k)): Next 'vul de 2e array met de echte waarden
If VarType(Arr_Exclusives) <> 0 Then
For Each el In Arr_Exclusives
s1 = Replace(Replace(Arr2(r - 1), Mid(el, 1, 1), "", , , vbTextCompare), Mid(el, 2, 1), "", , , vbTextCompare)
If -Len(s1) + Len(Arr2(r - 1)) >= 2 Then Arr2(r - 1) = "~": Exit For
Next
End If
Next
fl = Filter(Arr2, "~", 0, vbTextCompare)
MyResult = fl
If UBound(fl) < 65530 Then
arr3 = Application.Transpose(fl)
Else
ReDim arr3(1 To UBound(fl) + 1, 1 To 1)
For i = 0 To UBound(fl): arr3(i + 1, 1) = fl(i): Next
End If
'MsgBox Timer - t
'r1 = 50000
'MsgBox r1 & " " & arr3(r1, 1) & " " & MyResult(r1 - 1) & vbLf & 10 & " " & arr3(10, 1) & " " & MyResult(9)
End Sub