code modification VBA

julien clerc

XLDnaute Junior
bonjour à tous j'ai un énorme casse tête :
sur une série de combinaisons de 5 numéros je souhaite modifier ma vba pour ne garder que les combinaison ou figure mon chiffre fétiche:le 7 . voila ma vba :Sub combinaisons()
lin = 1
col = 1
For m = 1 To 49
For n = m + 1 To 49
For o = n + 1 To 49
For p = o + 1 To 49
For q = p + 1 To 49
Cells(lin, col) = m & " " & n & " " & " " & o & " " & p & " " & q
lin = lin + 1
If lin > 65536 Then
col = col + 1
lin = 1
End If
Next q
Next p
Next o
Next n
Next m
End Sub

Merci de votre aides
 

Pierrot93

XLDnaute Barbatruc
Re : code modification VBA

Re,

essaye en modifiant comme suit :
Code:
Option Explicit
Sub test()
Dim t() As Variant, m, n, o, p, q, lin, col
lin = 1
col = 1
For m = 1 To 49
For n = m + 1 To 49
For o = n + 1 To 49
For p = o + 1 To 49
For q = p + 1 To 49
t = Array(m, n, o, p, q)
If Not IsError(Application.Match(7, t, 0)) Then
    Cells(lin, col) = m & " " & n & " " & " " & o & " " & p & " " & q
    lin = lin + 1
    If lin > 65536 Then col = col + 1: lin = 1
End If
Erase t
Next q
Next p
Next o
Next n
Next m
End Sub

Edition : attention avec "option explicit" toutes les variables doivent être déclarées....
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
311 730
Messages
2 081 981
Membres
101 855
dernier inscrit
alexis345