Option Explicit
Sub hghgfh()
Call CombinaSel2(49)
End Sub
Sub CombinaSel2(c%)
'affiche les combinaisons à partir des choix en lignes 1 à 5.
'aucun controles de cohérence des entrées
'Que des n° différents OU certaines lignes identiques les unes sous les autres
Dim Mx%, Col%, Tb%(), i%, j%, Tm%(1 To 5), n1%, n2%, n3%, n4%, n5%, Ts$(), nL&, b(1 To 5) As Boolean, d%(1 To 4)
Application.ScreenUpdating = False
For i = 1 To 5
Tm(i) = Cells(i, Columns.Count).End(xlToLeft).Column
If Tm(i) > Mx Then Mx = Tm(i)
Next i
ReDim Tb(1 To 5, 1 To Mx)
For i = 1 To 5
b(1) = True
For j = 1 To Mx
Tb(i, j) = Cells(i, j)
If i > 1 And b(1) Then
If Tb(i, j) <> Tb(i - 1, j) Then b(1) = False
End If
Next j
If i > 1 And b(1) Then b(i) = True
Next i
Col = 1
Sheets.Add
For n1 = 1 To Tm(1)
If b(2) Then d(1) = n1 + 1 Else d(1) = 1
For n2 = d(1) To Tm(2)
If b(3) Then d(2) = n2 + 1 Else d(2) = 1
For n3 = d(2) To Tm(3)
If b(4) Then d(3) = n3 + 1 Else d(3) = 1
For n4 = d(3) To Tm(4)
If b(5) Then d(4) = n4 + 1 Else d(4) = 1
For n5 = d(4) To Tm(5)
If Tb(1, n1) <> Tb(2, n2) And Tb(1, n1) <> Tb(3, n3) And _
Tb(1, n1) <> Tb(4, n4) And Tb(1, n1) <> Tb(5, n5) And _
Tb(2, n2) <> Tb(3, n3) And Tb(2, n2) <> Tb(4, n4) And _
Tb(2, n2) <> Tb(5, n5) And Tb(3, n3) <> Tb(4, n4) And _
Tb(3, n3) <> Tb(5, n5) And Tb(4, n4) <> Tb(5, n5) Then
nL = nL + 1
ReDim Preserve Ts(1 To nL)
Ts(nL) = Tb(1, n1) & " " & Tb(2, n2) & " " & Tb(3, n3) & " " & _
Tb(4, n4) & " " & Tb(5, n5)
If nL = Rows.Count Then
Range(Cells(1, Col), Cells(Rows.Count, Col)).Value = Application.Transpose(Ts)
Col = Col + 1
nL = 0
End If
End If
Next
Next
Next
Next
Next
If nL <> 0 Then Range(Cells(1, Col), Cells(nL, Col)).Value = Application.Transpose(Ts)
Application.ScreenUpdating = True
End Sub