J
JJ1
Guest
Bonjour,
J'ai une macro dans un fichier Excel (il me semble réalisée par Job75).
Cette macro prend 20 nombres de A2 à T2 et restitue des combinaisons de 3 nombres (parmi 20) colonnes AW:AY avec le nombre col BB et l'écart col BC dans la plage.
dont je voudrais modifier 2 paramètres:
- uniquement 13 nombres (au lieu de 20) donc U2:M2
- combinaisons de 4 nombres au lieu de 3 (donc Col AW:AZ au lieu de AY)
Le reste inchangé.
Voici le code:
Sub calcul()
Dim tps As Double, tablo(19), i As Byte, j As Byte, k As Byte
Dim t1(65532), t2(65532), t3(65532)
Dim x As Integer, r As Range, c As Byte, nb(65532), ligne(65532)
Range("AW2:BC10000").ClearContents
tps = Now
Application.ScreenUpdating = False
For i = 0 To 19
tablo(i) = Cells(2, i + 1)
Next
For i = 0 To 17
For j = i + 1 To 18
For k = j + 1 To 19
t1(x) = tablo(i)
t2(x) = tablo(j)
t3(x) = tablo(k)
c = 0
For Each r In [plage].Rows 'recherche la combinaison dans [plage]
If IsError(Application.Match(t1(x), r, 0)) Then GoTo 1
If IsError(Application.Match(t2(x), r, 0)) Then GoTo 1
If IsError(Application.Match(t3(x), r, 0)) Then GoTo 1
c = c + 1
If c = 1 Then ligne(x) = r.Row '1ère ligne trouvée
1 Next
nb(x) = c 'comptage
x = x + 1
Next
Next
Next
Range("AW2:AW" & x + 3).Value = Application.Transpose(t1)
Range("AX2:AX" & x + 3).Value = Application.Transpose(t2)
Range("AY2:AY" & x + 3).Value = Application.Transpose(t3)
Range("BB2:BB" & x + 3).Value = Application.Transpose(nb)
Range("BC2:BC" & x + 3).Value = Application.Transpose(ligne)
Range("A4:J65536").Sort Key1:=Range("H4"), Order1:=xlDescending, _
Key2:=Range("J4"), Order2:=xlAscending, Header:=xlNo
Application.ScreenUpdating = True
MsgBox Chr(10) & "Nombre de combinaisons : " & x & Chr(10) & Chr(10) & _
"Combinaisons dans la plage : " & Application.Sum(Range("H4:H65536")) & " " & Chr(10) & Chr(10) & _
"Durée du calcul : " & Format(Now - tps, "h ""mn"" s ""s""") & Chr(10)
End Sub
Merci d'avance
Bon dimanche
J'ai une macro dans un fichier Excel (il me semble réalisée par Job75).
Cette macro prend 20 nombres de A2 à T2 et restitue des combinaisons de 3 nombres (parmi 20) colonnes AW:AY avec le nombre col BB et l'écart col BC dans la plage.
dont je voudrais modifier 2 paramètres:
- uniquement 13 nombres (au lieu de 20) donc U2:M2
- combinaisons de 4 nombres au lieu de 3 (donc Col AW:AZ au lieu de AY)
Le reste inchangé.
Voici le code:
Sub calcul()
Dim tps As Double, tablo(19), i As Byte, j As Byte, k As Byte
Dim t1(65532), t2(65532), t3(65532)
Dim x As Integer, r As Range, c As Byte, nb(65532), ligne(65532)
Range("AW2:BC10000").ClearContents
tps = Now
Application.ScreenUpdating = False
For i = 0 To 19
tablo(i) = Cells(2, i + 1)
Next
For i = 0 To 17
For j = i + 1 To 18
For k = j + 1 To 19
t1(x) = tablo(i)
t2(x) = tablo(j)
t3(x) = tablo(k)
c = 0
For Each r In [plage].Rows 'recherche la combinaison dans [plage]
If IsError(Application.Match(t1(x), r, 0)) Then GoTo 1
If IsError(Application.Match(t2(x), r, 0)) Then GoTo 1
If IsError(Application.Match(t3(x), r, 0)) Then GoTo 1
c = c + 1
If c = 1 Then ligne(x) = r.Row '1ère ligne trouvée
1 Next
nb(x) = c 'comptage
x = x + 1
Next
Next
Next
Range("AW2:AW" & x + 3).Value = Application.Transpose(t1)
Range("AX2:AX" & x + 3).Value = Application.Transpose(t2)
Range("AY2:AY" & x + 3).Value = Application.Transpose(t3)
Range("BB2:BB" & x + 3).Value = Application.Transpose(nb)
Range("BC2:BC" & x + 3).Value = Application.Transpose(ligne)
Range("A4:J65536").Sort Key1:=Range("H4"), Order1:=xlDescending, _
Key2:=Range("J4"), Order2:=xlAscending, Header:=xlNo
Application.ScreenUpdating = True
MsgBox Chr(10) & "Nombre de combinaisons : " & x & Chr(10) & Chr(10) & _
"Combinaisons dans la plage : " & Application.Sum(Range("H4:H65536")) & " " & Chr(10) & Chr(10) & _
"Durée du calcul : " & Format(Now - tps, "h ""mn"" s ""s""") & Chr(10)
End Sub
Merci d'avance
Bon dimanche