cortadillo
XLDnaute Nouveau
Bonjour les amis,
j'ai un big problème aujourd'hui, j'ai réalisé un petit tableau excel dont l'objectif est de mettre différent couleur de fond de cellule en fonction du numéro index.
j'ai en effet mis en place une colonne index qui me permet d'attribuer un groupe de couleur.
Problème n°1=> mon index est à 38 ce qui est supérieur au code colorIndex.
Problème n°2=> j'ai découvert un bug dans mon code puisque dans le groupe index n°22 j'ai différente couleur!! cf. ligne 960 du fichier joint. donc ce n'est pas bon.
Quelqu'un peut il me apporter assistance pour corriger mon code.
Encore merci.
ci-joint le fichier et la macro
le code vba est le suivant:
Sub MFC_Couleur()
Application.ScreenUpdating = False
Sheets("Données Maitre MOE").Visible = True
Sheets("Données Maitre MOE").Select
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Set mondico = CreateObject("Scripting.Dictionary")
For Each Cel In Range("I2:i" & Range("I65536").End(xlUp).Row)
If Not mondico.Exists(Cel.Value) Then mondico.Add Cel.Value, Cel.Value
Next
For Each Item In mondico.items
If Item <> "" Then
couleur = 35 + Item
Else
Item = 0
couleur = 0
Exit Sub
End If
Set c = Columns("I").Find(Item, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
ld = c.Row: lf = ld - 1
Do
lf = lf + 1
Set c = Columns("i").FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
Range(Cells(ld, 1), Cells(lf, 9)).Interior.ColorIndex = couleur
End If
Range(Cells(ld, 1), Cells(lf, 9)).Interior.ColorIndex = couleur
lf = 0
j'ai un big problème aujourd'hui, j'ai réalisé un petit tableau excel dont l'objectif est de mettre différent couleur de fond de cellule en fonction du numéro index.
j'ai en effet mis en place une colonne index qui me permet d'attribuer un groupe de couleur.
Problème n°1=> mon index est à 38 ce qui est supérieur au code colorIndex.
Problème n°2=> j'ai découvert un bug dans mon code puisque dans le groupe index n°22 j'ai différente couleur!! cf. ligne 960 du fichier joint. donc ce n'est pas bon.
Quelqu'un peut il me apporter assistance pour corriger mon code.
Encore merci.
ci-joint le fichier et la macro
le code vba est le suivant:
Sub MFC_Couleur()
Application.ScreenUpdating = False
Sheets("Données Maitre MOE").Visible = True
Sheets("Données Maitre MOE").Select
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Set mondico = CreateObject("Scripting.Dictionary")
For Each Cel In Range("I2:i" & Range("I65536").End(xlUp).Row)
If Not mondico.Exists(Cel.Value) Then mondico.Add Cel.Value, Cel.Value
Next
For Each Item In mondico.items
If Item <> "" Then
couleur = 35 + Item
Else
Item = 0
couleur = 0
Exit Sub
End If
Set c = Columns("I").Find(Item, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
ld = c.Row: lf = ld - 1
Do
lf = lf + 1
Set c = Columns("i").FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
Range(Cells(ld, 1), Cells(lf, 9)).Interior.ColorIndex = couleur
End If
Range(Cells(ld, 1), Cells(lf, 9)).Interior.ColorIndex = couleur
lf = 0