1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| Option Explicit
Dim iLignes As Integer
Dim iColonnes As Integer
Dim iLongueur As Integer
Dim vLargeurs() As Variant
Const scSignes = "C7"
Const scParam = "K2"
Const scSortie = "K7"
Sub Go()
Dim vSignes() As Variant
Dim i As Integer
Dim j As Integer
Dim lSol As Long
'chargement des valeurs
iLignes = Range(scParam).Value
iColonnes = Range(scParam).Offset(1).Value
iLongueur = Range(scParam).Offset(2).Value
vSignes = Range(scSignes).Resize(iLignes, iColonnes).Value
vLargeurs = Range(scSignes).Offset(0, -1).Resize(iLignes).Value
' préparation de la sortie : effacement éventuel.
ActiveSheet.Unprotect
If Range(scSortie).Cells.Count = 1 Then
Range(scSortie, Range(scSortie).End(xlDown)).Clear
End If
' génération des combinaisons
Combine vSignes, lSol
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Sub Combine(vSignes, ByRef lSol, Optional nSol = 0, Optional N = 1, Optional Ni = 0, Optional S = "")
Dim OldS As String
Dim i As Integer
Dim j As Integer
OldS = S
If Ni + (iLongueur - N) <= iLignes Then
For i = Ni + 1 To iLignes
For j = 1 To vLargeurs(i, 1)
S = S & vSignes(i, j)
If N < iLongueur Then
Combine vSignes, lSol, nSol, N + 1, i, S
Else
nSol = nSol + 1
Range(scSortie).Offset(nSol - 1).Value = S
End If
S = OldS
Next j
Next i
End If
Range(scParam).Offset(3).Value = nSol
End Sub |
Partager