Colorer une ligne avec conditions

Résolu
Pimp92a Messages postés 417 Date d'inscription   Statut Membre Dernière intervention   -  
Pimp92a Messages postés 417 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour le forum,

je dois colorer des lignes selon des conditions spécifiques.

J'ai fait une boucle pour tester ces conditions sur toutes les lignes à chaque fois.

En gros ça fait si excel trouve "x" dans la colonne G sur la ligne 1 alors colorer la ligne en jaune
Même chose pour ligne 2, 3, 4, 5, etc...

Si excel trouve "y" dans la colonne h et "z" dans la colonne i sur la ligne 1, alors colorer en vert.
Même chose pour la ligne 2,3,4,5, etc...

Le problème est que dès qu'il ne trouve plus les conditions pour une couleur, alors il ne cherche plus pour les couleurs suivantes.

Voici mon code :

Sub Macro()
Dim g As Integer
Dim h As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Integer
Dim n As Integer


Do
g = g + 1
Loop While Cells(9, g) <> "RENEWAL TYPE "



i = 10


While Cells(i, g) = "DNR"

Cells(i, 1).Interior.ColorIndex = 16
Cells(i, 2).Interior.ColorIndex = 16
Cells(i, 3).Interior.ColorIndex = 16
Cells(i, 4).Interior.ColorIndex = 16
Cells(i, 5).Interior.ColorIndex = 16
Cells(i, 6).Interior.ColorIndex = 16
Cells(i, 7).Interior.ColorIndex = 16
Cells(i, 8).Interior.ColorIndex = 16
Cells(i, 9).Interior.ColorIndex = 16
Cells(i, 10).Interior.ColorIndex = 16
Cells(i, 11).Interior.ColorIndex = 16
Cells(i, 12).Interior.ColorIndex = 16
Cells(i, 13).Interior.ColorIndex = 16
Cells(i, 14).Interior.ColorIndex = 16
Cells(i, 15).Interior.ColorIndex = 16
Cells(i, 16).Interior.ColorIndex = 16
Cells(i, 17).Interior.ColorIndex = 16
Cells(i, 18).Interior.ColorIndex = 16
Cells(i, 19).Interior.ColorIndex = 16
Cells(i, 20).Interior.ColorIndex = 16
Cells(i, 21).Interior.ColorIndex = 16
Cells(i, 22).Interior.ColorIndex = 16
Cells(i, 23).Interior.ColorIndex = 16
Cells(i, 24).Interior.ColorIndex = 16
Cells(i, 25).Interior.ColorIndex = 16
Cells(i, 26).Interior.ColorIndex = 16
Cells(i, 27).Interior.ColorIndex = 16
Cells(i, 28).Interior.ColorIndex = 16
Cells(i, 29).Interior.ColorIndex = 16
Cells(i, 30).Interior.ColorIndex = 16
Cells(i, 31).Interior.ColorIndex = 16
Cells(i, 32).Interior.ColorIndex = 16
Cells(i, 33).Interior.ColorIndex = 16
Cells(i, 34).Interior.ColorIndex = 16
Cells(i, 35).Interior.ColorIndex = 16
Cells(i, 36).Interior.ColorIndex = 16
Cells(i, 37).Interior.ColorIndex = 16
Cells(i, 38).Interior.ColorIndex = 16


i = i + 1
Wend
Do
h = h + 1
j = j + 1
k = k + 1
l = l + 1
n = n + 1
o = o + 1
Loop While Cells(9, h) <> "SERIAL NUMBER STATUS"
While Cells(i, g) = "FUL" And Cells(i, h) = "Active" Or Cells(i, g) = "FUL" And Cells(i, j) = "Active Subscription" Or Cells(i, g) = "FUL" And Cells(i, k) = "Active Split" Or Cells(i, g) = "FUL" And Cells(i, l) = "VM Enriched" Or Cells(i, g) = "FUL" And Cells(i, n) = "Active Merge" Or Cells(i, g) = "FUL" And Cells(i, o) = "VM Upgraded"




Cells(i, 1).Interior.ColorIndex = 6
Cells(i, 2).Interior.ColorIndex = 6
Cells(i, 3).Interior.ColorIndex = 6
Cells(i, 4).Interior.ColorIndex = 6
Cells(i, 5).Interior.ColorIndex = 6
Cells(i, 6).Interior.ColorIndex = 6
Cells(i, 7).Interior.ColorIndex = 6
Cells(i, 8).Interior.ColorIndex = 6
Cells(i, 9).Interior.ColorIndex = 6
Cells(i, 10).Interior.ColorIndex = 6
Cells(i, 11).Interior.ColorIndex = 6
Cells(i, 12).Interior.ColorIndex = 6
Cells(i, 13).Interior.ColorIndex = 6
Cells(i, 14).Interior.ColorIndex = 6
Cells(i, 15).Interior.ColorIndex = 6
Cells(i, 16).Interior.ColorIndex = 6
Cells(i, 17).Interior.ColorIndex = 6
Cells(i, 18).Interior.ColorIndex = 6
Cells(i, 19).Interior.ColorIndex = 6
Cells(i, 20).Interior.ColorIndex = 6
Cells(i, 21).Interior.ColorIndex = 6
Cells(i, 22).Interior.ColorIndex = 6
Cells(i, 23).Interior.ColorIndex = 6
Cells(i, 24).Interior.ColorIndex = 6
Cells(i, 25).Interior.ColorIndex = 6
Cells(i, 26).Interior.ColorIndex = 6
Cells(i, 27).Interior.ColorIndex = 6
Cells(i, 28).Interior.ColorIndex = 6
Cells(i, 29).Interior.ColorIndex = 6
Cells(i, 30).Interior.ColorIndex = 6
Cells(i, 31).Interior.ColorIndex = 6
Cells(i, 32).Interior.ColorIndex = 6
Cells(i, 33).Interior.ColorIndex = 6
Cells(i, 34).Interior.ColorIndex = 6
Cells(i, 35).Interior.ColorIndex = 6
Cells(i, 36).Interior.ColorIndex = 6
Cells(i, 37).Interior.ColorIndex = 6
Cells(i, 38).Interior.ColorIndex = 6


i = i + 1
Wend



Do
m = m + 1
Loop While Cells(9, m) <> "SERIAL NUMBER STATUS"
While Cells(i, g) = "FUL" And Cells(i, m) = "Subscription Fulfilled"

Cells(i, 1).Interior.ColorIndex = 15
Cells(i, 2).Interior.ColorIndex = 15
Cells(i, 3).Interior.ColorIndex = 15
Cells(i, 4).Interior.ColorIndex = 15
Cells(i, 5).Interior.ColorIndex = 15
Cells(i, 6).Interior.ColorIndex = 15
Cells(i, 7).Interior.ColorIndex = 15
Cells(i, 8).Interior.ColorIndex = 15
Cells(i, 9).Interior.ColorIndex = 15
Cells(i, 10).Interior.ColorIndex = 15
Cells(i, 11).Interior.ColorIndex = 15
Cells(i, 12).Interior.ColorIndex = 15
Cells(i, 13).Interior.ColorIndex = 15
Cells(i, 14).Interior.ColorIndex = 15
Cells(i, 15).Interior.ColorIndex = 15
Cells(i, 16).Interior.ColorIndex = 15
Cells(i, 17).Interior.ColorIndex = 15
Cells(i, 18).Interior.ColorIndex = 15
Cells(i, 19).Interior.ColorIndex = 15
Cells(i, 20).Interior.ColorIndex = 15
Cells(i, 21).Interior.ColorIndex = 15
Cells(i, 22).Interior.ColorIndex = 15
Cells(i, 23).Interior.ColorIndex = 15
Cells(i, 24).Interior.ColorIndex = 15
Cells(i, 25).Interior.ColorIndex = 15
Cells(i, 26).Interior.ColorIndex = 15
Cells(i, 27).Interior.ColorIndex = 15
Cells(i, 28).Interior.ColorIndex = 15
Cells(i, 29).Interior.ColorIndex = 15
Cells(i, 30).Interior.ColorIndex = 15
Cells(i, 31).Interior.ColorIndex = 15
Cells(i, 32).Interior.ColorIndex = 15
Cells(i, 33).Interior.ColorIndex = 15
Cells(i, 34).Interior.ColorIndex = 15
Cells(i, 35).Interior.ColorIndex = 15
Cells(i, 36).Interior.ColorIndex = 15
Cells(i, 37).Interior.ColorIndex = 15
Cells(i, 38).Interior.ColorIndex = 15

i = i + 1
Wend





End Sub
A voir également:

3 réponses

lermite222 Messages postés 8724 Date d'inscription   Statut Contributeur Dernière intervention   1 191
 
Bonjour,
Heu... t'aurais peut-être pu trouver un peu plus compliquer !!.. -:) (c'est pour rire)
Dans tes explications tu ne parle que de deux couleurs mais dans ton code il y en a trois ?
J'ai fait suivant tes explications (2 couleurs)
Sub Test2()
Dim Lig As Long
    For Lig = 1 To Sheets("Feuil1").Range("A1").SpecialCells(xlCellTypeLastCell).Row
        If Cells(Lig, 7) = "x" Then
            Rows(Lig).Interior.ColorIndex = 6
        ElseIf Cells(Lig, 8) = "y" And Cells(Lig, 9) = "z" Then
            Rows(Lig).Interior.ColorIndex = 15
        Else
            Rows(Lig).Interior.ColorIndex = xlNone
        End If
    Next Lig
End Sub

A+
0
Pimp92a Messages postés 417 Date d'inscription   Statut Membre Dernière intervention   44
 
Bonsoir lermite,

Merci de me consacrer un peu de temps, c'est très gentil à toi :)

Effectivement, dans mon code, il y a trois couleurs, mon explication voulait etre le plus synthétique possible, mais il peut y avoir 10 couleurs, je voulais avoir l'explication générale pour pouvoir adapter ton code pour mon classeur. J'essaye ton code de suite, et je te tiens au courant.

Merci encore
0
Pimp92a Messages postés 417 Date d'inscription   Statut Membre Dernière intervention   44
 
C'est tout à fait bon,

Merci lermite ;)
0