Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

code vba pour afficher une combinaison en couleur

Fred0o

XLDnaute Barbatruc
Re : code vba pour afficher une combinaison en couleur

Bonjour julien,

En gros, tu ne nous donnes rien et nous, on devrait tout de donner...

Si tu veux qu'on t'aide, il faut nous fournir ton code VBA et un fichier exemple. Sinon, tu restera avec ta question.

A+
 

julien clerc

XLDnaute Junior
Re : code vba pour afficher une combinaison en couleur

désolé Fredo

Sub combinaisons()
lin = 1
col = 1
For m = 1 To 20
For n = m + 1 To 20
For o = n + 1 To 20
For p = o + 1 To 20
For q = p + 1 To 20
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
 

Fred0o

XLDnaute Barbatruc
Re : code vba pour afficher une combinaison en couleur

Re-bonjour,

Si j'ai bien tout compris, tu peux essayer le code suivant :
VB:
Sub combinaisons()
    lin = 1
    col = 1
    For m = 1 To 20
        For n = m + 1 To 20
            For o = n + 1 To 20
                For p = o + 1 To 20
                    For q = p + 1 To 20
                        Cells(lin, col) = m & " " & n & " " & o & " " & p & " " & q
                        If Cells(lin, col) = "1 2 3 4 5" Then
                            Cells(lin, col).Font.ColorIndex = 3
                        End If
                        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

A+
 

julien clerc

XLDnaute Junior
Re : code vba pour afficher une combinaison en couleur

re fredo j'ai un petit problème, je ne trouve pas le code exacte pour modifier ma vba
car quant je lance ma vba j'ai le message suivent : mémoire insuffisante . voici ma combinaison
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 > 10 Then
col = col + 1
lin = 1
End If
Next q
Next p
Next o
Next n
Next m
End Sub

Merci de ton aide
 

Fred0o

XLDnaute Barbatruc
Re : code vba pour afficher une combinaison en couleur

Re-onjour,

C'est normal, ton code dépasse les capacités d'EXCEL; si tu change de colonne toutes les 10 combinaisons, sachant qu'EXCEL 2010 a une capacité de 16384 colonnes, tu ne peux avoir que 163840 combinaisons. Or, tu en as largement plus. Je te conseille donc de changer de colonne toutes les 1000 combinaisons. Ton code devient donc :
VB:
Sub combinaisons()
    Application.ScreenUpdating = False
    Cells.ClearContents
    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 > 1000 Then
                            col = col + 1
                            lin = 1
                        End If
                    Next q
                Next p
            Next o
        Next n
    Next m
    Application.ScreenUpdating = True
End Sub

A+
 

Discussions similaires

Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…