Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Mise en forme Cond.

13 réponses
Avatar
Michel69
Bonjour à toutes et à tous,
Excel 2003 : Pourriez-vous m'aider ?
Comment, en VBA, colorer une ligne (col A à BE) en fonction d'un critère se
trouvant en col AN.
ex : si de an3:an500 j'ai les mots "défavorable", je souhaiterais colorer
les lignes crorrespondantes en marron (40). Puis-je programmer plusieurs
conditions dans le même code (WorksheetSelection_Change ?).
Merci pour tout
Michel69

10 réponses

1 2
Avatar
Daniel.C
Bonjour.
Tu peux mettre une mise en forme conditionnelle, soit par VBA, soit
manuellement ou utiliser la macro évènementielle suivante (à mettre
dans le module de la feuille) :

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([AN3:AN500], Target)
If c.Value = "défavorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row,
"BE")).Interior.ColorIndex = 40
End If
Next c
Application.EnableEvents = True
End Sub

Cordialement.
Daniel

Bonjour à toutes et à tous,
Excel 2003 : Pourriez-vous m'aider ?
Comment, en VBA, colorer une ligne (col A à BE) en fonction d'un critère se
trouvant en col AN.
ex : si de an3:an500 j'ai les mots "défavorable", je souhaiterais colorer
les lignes crorrespondantes en marron (40). Puis-je programmer plusieurs
conditions dans le même code (WorksheetSelection_Change ?).
Merci pour tout
Michel69


Avatar
Daniel.C
Et pour effacer le coloriage si la cellule change de valeur :

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([AN3:AN500], Target)
If c.Value = "défavorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row,
"BE")).Interior.ColorIndex = 40
Else
Range(Cells(c.Row, "A"), Cells(c.Row,
"BE")).Interior.ColorIndex = xlNone
End If
Next c
Application.EnableEvents = True
End Sub

Daniel

Bonjour à toutes et à tous,
Excel 2003 : Pourriez-vous m'aider ?
Comment, en VBA, colorer une ligne (col A à BE) en fonction d'un critère se
trouvant en col AN.
ex : si de an3:an500 j'ai les mots "défavorable", je souhaiterais colorer
les lignes crorrespondantes en marron (40). Puis-je programmer plusieurs
conditions dans le même code (WorksheetSelection_Change ?).
Merci pour tout
Michel69


Avatar
Michel69
Bonjour Daniel.C et merci pour ta solution
Si j'ai d'autre couleur à générer avec d'autres critères sur d'autres
colonnes est-ce que je peux enchainer les if intersect.....end if ?
Merci encore
Michel

"Daniel.C" a écrit :

Bonjour.
Tu peux mettre une mise en forme conditionnelle, soit par VBA, soit
manuellement ou utiliser la macro évènementielle suivante (à mettre
dans le module de la feuille) :

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([AN3:AN500], Target)
If c.Value = "défavorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row,
"BE")).Interior.ColorIndex = 40
End If
Next c
Application.EnableEvents = True
End Sub

Cordialement.
Daniel

> Bonjour à toutes et à tous,
> Excel 2003 : Pourriez-vous m'aider ?
> Comment, en VBA, colorer une ligne (col A à BE) en fonction d'un critère se
> trouvant en col AN.
> ex : si de an3:an500 j'ai les mots "défavorable", je souhaiterais colorer
> les lignes crorrespondantes en marron (40). Puis-je programmer plusieurs
> conditions dans le même code (WorksheetSelection_Change ?).
> Merci pour tout
> Michel69





Avatar
MichDenis
Oui tu peux le faire. En reprenant le code de Daniel pour les fins
de l'illustration, ce pourrait donner quelque chose comme ça si
tu as 2 plages distinctes... et tu peux ajouter d'autres plages le
cas échéant.


Private Sub Worksheet_Change(ByVal Target As Range)

Dim c As Range
'Plage No1
If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([AN3:AN500], Target)
If c.Value = "défavorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = 40
Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = xlNone
End If
Next c
Application.EnableEvents = True
End If

'Plage No2
If Intersect([B1:B25], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([B1:B25], Target)
If c.Value = "favorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = 40
Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = xlNone
End If
Next c
Application.EnableEvents = True
End If
End Sub




"Michel69" a écrit dans le message de groupe de
discussion :
Bonjour Daniel.C et merci pour ta solution
Si j'ai d'autre couleur à générer avec d'autres critères sur d'autres
colonnes est-ce que je peux enchainer les if intersect.....end if ?
Merci encore
Michel

"Daniel.C" a écrit :

Bonjour.
Tu peux mettre une mise en forme conditionnelle, soit par VBA, soit
manuellement ou utiliser la macro évènementielle suivante (à mettre
dans le module de la feuille) :

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([AN3:AN500], Target)
If c.Value = "défavorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row,
"BE")).Interior.ColorIndex = 40
End If
Next c
Application.EnableEvents = True
End Sub

Cordialement.
Daniel

> Bonjour à toutes et à tous,
> Excel 2003 : Pourriez-vous m'aider ?
> Comment, en VBA, colorer une ligne (col A à BE) en fonction d'un critère se
> trouvant en col AN.
> ex : si de an3:an500 j'ai les mots "défavorable", je souhaiterais colorer
> les lignes crorrespondantes en marron (40). Puis-je programmer plusieurs
> conditions dans le même code (WorksheetSelection_Change ?).
> Merci pour tout
> Michel69





Avatar
Michel69
Bonjour MichDenis et merci pour ton aide.
Je vais essayer tout de suite. Je vous tiens au courant
Michel

"MichDenis" a écrit :

Oui tu peux le faire. En reprenant le code de Daniel pour les fins
de l'illustration, ce pourrait donner quelque chose comme ça si
tu as 2 plages distinctes... et tu peux ajouter d'autres plages le
cas échéant.


Private Sub Worksheet_Change(ByVal Target As Range)

Dim c As Range
'Plage No1
If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([AN3:AN500], Target)
If c.Value = "défavorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = 40
Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = xlNone
End If
Next c
Application.EnableEvents = True
End If

'Plage No2
If Intersect([B1:B25], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([B1:B25], Target)
If c.Value = "favorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = 40
Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = xlNone
End If
Next c
Application.EnableEvents = True
End If
End Sub




"Michel69" a écrit dans le message de groupe de
discussion :
Bonjour Daniel.C et merci pour ta solution
Si j'ai d'autre couleur à générer avec d'autres critères sur d'autres
colonnes est-ce que je peux enchainer les if intersect.....end if ?
Merci encore
Michel

"Daniel.C" a écrit :

> Bonjour.
> Tu peux mettre une mise en forme conditionnelle, soit par VBA, soit
> manuellement ou utiliser la macro évènementielle suivante (à mettre
> dans le module de la feuille) :
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim c As Range
> If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
> Application.EnableEvents = False
> For Each c In Intersect([AN3:AN500], Target)
> If c.Value = "défavorable" Then
> Range(Cells(c.Row, "A"), Cells(c.Row,
> "BE")).Interior.ColorIndex = 40
> End If
> Next c
> Application.EnableEvents = True
> End Sub
>
> Cordialement.
> Daniel
>
> > Bonjour à toutes et à tous,
> > Excel 2003 : Pourriez-vous m'aider ?
> > Comment, en VBA, colorer une ligne (col A à BE) en fonction d'un critère se
> > trouvant en col AN.
> > ex : si de an3:an500 j'ai les mots "défavorable", je souhaiterais colorer
> > les lignes crorrespondantes en marron (40). Puis-je programmer plusieurs
> > conditions dans le même code (WorksheetSelection_Change ?).
> > Merci pour tout
> > Michel69
>
>
>




Avatar
Michel69
MichDenis bonjour et encore merci à tous les 2. J'avais envisagé le cas donc
j'ai codé comme ceci :
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Worksheets("BDD").Columns("A:bz").AutoFit
Dim c As Range
If Intersect([be3:be500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([be3:be500], Target)
If c.Value = "défavorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex = 40
Next c
If c.Value = "très défavorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex = 40
End If
Next c
If c.Value = "" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex =
xlNone
End If
Next c
If c.Value = "favorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex = 34
End If
Next c
If c.Value = "très favorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex = 34
End If
Next c

If Intersect([an3:an500], Target) Is Nothing Then Exit Sub
For Each c In Intersect([an3:an500], Target)
If c.Value <> "" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex = 4
End If
Next c
Application.EnableEvents = True
End Sub
mais celà ne fonctionne pas ?? Rien ne se passe
Merci encore
Michel

"MichDenis" a écrit :

Oui tu peux le faire. En reprenant le code de Daniel pour les fins
de l'illustration, ce pourrait donner quelque chose comme ça si
tu as 2 plages distinctes... et tu peux ajouter d'autres plages le
cas échéant.


Private Sub Worksheet_Change(ByVal Target As Range)

Dim c As Range
'Plage No1
If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([AN3:AN500], Target)
If c.Value = "défavorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = 40
Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = xlNone
End If
Next c
Application.EnableEvents = True
End If

'Plage No2
If Intersect([B1:B25], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([B1:B25], Target)
If c.Value = "favorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = 40
Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = xlNone
End If
Next c
Application.EnableEvents = True
End If
End Sub




"Michel69" a écrit dans le message de groupe de
discussion :
Bonjour Daniel.C et merci pour ta solution
Si j'ai d'autre couleur à générer avec d'autres critères sur d'autres
colonnes est-ce que je peux enchainer les if intersect.....end if ?
Merci encore
Michel

"Daniel.C" a écrit :

> Bonjour.
> Tu peux mettre une mise en forme conditionnelle, soit par VBA, soit
> manuellement ou utiliser la macro évènementielle suivante (à mettre
> dans le module de la feuille) :
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim c As Range
> If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
> Application.EnableEvents = False
> For Each c In Intersect([AN3:AN500], Target)
> If c.Value = "défavorable" Then
> Range(Cells(c.Row, "A"), Cells(c.Row,
> "BE")).Interior.ColorIndex = 40
> End If
> Next c
> Application.EnableEvents = True
> End Sub
>
> Cordialement.
> Daniel
>
> > Bonjour à toutes et à tous,
> > Excel 2003 : Pourriez-vous m'aider ?
> > Comment, en VBA, colorer une ligne (col A à BE) en fonction d'un critère se
> > trouvant en col AN.
> > ex : si de an3:an500 j'ai les mots "défavorable", je souhaiterais colorer
> > les lignes crorrespondantes en marron (40). Puis-je programmer plusieurs
> > conditions dans le même code (WorksheetSelection_Change ?).
> > Merci pour tout
> > Michel69
>
>
>




Avatar
Daniel.C
Essaie avec cette macro :

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Worksheets("BDD").Columns("A:bz").AutoFit
Dim c As Range
If Not Intersect([be3:be500], Target) Is Nothing Then
Application.EnableEvents = False
For Each c In Intersect([be3:be500], Target)
If c.Value = "défavorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row,
"BG")).Interior.ColorIndex = 40
If c.Value = "très défavorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row,
"BG")).Interior.ColorIndex = 40
End If
If c.Value = "" Then _
Range(Cells(c.Row, "A"), Cells(c.Row,
"BG")).Interior.ColorIndex = xlNone
End If
If c.Value = "favorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row,
"BG")).Interior.ColorIndex = 34
End If
If c.Value = "très favorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row,
"BG")).Interior.ColorIndex = 34
End If
Next c

ElseIf Not Intersect([an3:an500], Target) Is Nothing Then
For Each c In Intersect([an3:an500], Target)
If c.Value <> "" Then _
Range(Cells(c.Row, "A"), Cells(c.Row,
"BG")).Interior.ColorIndex = 4
End If
Next c
End If
Application.EnableEvents = True
End Sub

Daniel

MichDenis bonjour et encore merci à tous les 2. J'avais envisagé le cas donc
j'ai codé comme ceci :
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Worksheets("BDD").Columns("A:bz").AutoFit
Dim c As Range
If Intersect([be3:be500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([be3:be500], Target)
If c.Value = "défavorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex = 40
Next c
If c.Value = "très défavorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex = 40
End If
Next c
If c.Value = "" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex =
xlNone
End If
Next c
If c.Value = "favorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex = 34
End If
Next c
If c.Value = "très favorable" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex = 34
End If
Next c

If Intersect([an3:an500], Target) Is Nothing Then Exit Sub
For Each c In Intersect([an3:an500], Target)
If c.Value <> "" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")).Interior.ColorIndex = 4
End If
Next c
Application.EnableEvents = True
End Sub
mais celà ne fonctionne pas ?? Rien ne se passe
Merci encore
Michel

"MichDenis" a écrit :

Oui tu peux le faire. En reprenant le code de Daniel pour les fins
de l'illustration, ce pourrait donner quelque chose comme ça si
tu as 2 plages distinctes... et tu peux ajouter d'autres plages le
cas échéant.


Private Sub Worksheet_Change(ByVal Target As Range)

Dim c As Range
'Plage No1
If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([AN3:AN500], Target)
If c.Value = "défavorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = 40
Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = xlNone
End If
Next c
Application.EnableEvents = True
End If

'Plage No2
If Intersect([B1:B25], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([B1:B25], Target)
If c.Value = "favorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = 40
Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BE")). _
Interior.ColorIndex = xlNone
End If
Next c
Application.EnableEvents = True
End If
End Sub




"Michel69" a écrit dans le message de
groupe de discussion :
Bonjour Daniel.C et
merci pour ta solution Si j'ai d'autre couleur à générer avec d'autres
critères sur d'autres colonnes est-ce que je peux enchainer les if
intersect.....end if ? Merci encore
Michel

"Daniel.C" a écrit :

Bonjour.
Tu peux mettre une mise en forme conditionnelle, soit par VBA, soit
manuellement ou utiliser la macro évènementielle suivante (à mettre
dans le module de la feuille) :

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Intersect([AN3:AN500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([AN3:AN500], Target)
If c.Value = "défavorable" Then
Range(Cells(c.Row, "A"), Cells(c.Row,
"BE")).Interior.ColorIndex = 40
End If
Next c
Application.EnableEvents = True
End Sub

Cordialement.
Daniel

Bonjour à toutes et à tous,
Excel 2003 : Pourriez-vous m'aider ?
Comment, en VBA, colorer une ligne (col A à BE) en fonction d'un critère
se trouvant en col AN.
ex : si de an3:an500 j'ai les mots "défavorable", je souhaiterais colorer
les lignes crorrespondantes en marron (40). Puis-je programmer plusieurs
conditions dans le même code (WorksheetSelection_Change ?).
Merci pour tout
Michel69













Avatar
MichDenis
Il faut faire attention à cette ligne de code :
Application.EnableEvents = False

Elle désactive les procédures événementielles durant le traitement
des cellules concernées dans la procédure mais il ne faut pas oublier
de la remettre à True sinon la fois suivante que tu cliqueras dans
la feuille, la procédure ne sera pas déclenchée et rien ne se passera.

En conséquence, il faut faire un choix judicieux de l'emplacement de
ces deux lignes de code afin de s'assurer que peu importe où la
procédure se terminera, on remettra à True l'activation des
procédures événementielles.

Dans un premier temps :

Exécute une fois cette procédure :
Sub Reactiver_Procédures_événementielles()
Application.EnableEvents = True
End Sub

Dans un second temps : revois ta procédure et assure toi
que cette ligne de code sera exécutée avant la fin de la
procédure : Application.EnableEvents = True

L'autre aspect de ta problématique, c'est la manière dont tu as écris
tes conditions, ta procédure pourrait ressemble à ceci... assure toi
que tes conditions sont bien respectées.

'----------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range

Worksheets("BDD").Columns("A:bz").AutoFit

If Intersect([be3:be500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([be3:be500], Target)
Select Case LCase(c.Value)
Case Is = "défavorable", "très défavorable"
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = 40

Case Is = "favorable", "très favorable"
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = 34

Case Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = xlNone
End Select
Next c
Application.EnableEvents = True
End If

If Intersect([an3:an500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([an3:an500], Target)
If c.Value <> "" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = 4
End If
Next c
Application.EnableEvents = True
End If
End Sub
'----------------------------------------------
Avatar
Michel69
(Re)Bonjour MichDenis
Merci du temps que tu passes à mon Pb.
J'ai placé ton code dans la feuille.
Celà ne marche que pour la 1ère condition "défavorable","très défavorable".
pour les autres il semble les ignorer.
Cordialement
Michel

"MichDenis" a écrit :

Il faut faire attention à cette ligne de code :
Application.EnableEvents = False

Elle désactive les procédures événementielles durant le traitement
des cellules concernées dans la procédure mais il ne faut pas oublier
de la remettre à True sinon la fois suivante que tu cliqueras dans
la feuille, la procédure ne sera pas déclenchée et rien ne se passera.

En conséquence, il faut faire un choix judicieux de l'emplacement de
ces deux lignes de code afin de s'assurer que peu importe où la
procédure se terminera, on remettra à True l'activation des
procédures événementielles.

Dans un premier temps :

Exécute une fois cette procédure :
Sub Reactiver_Procédures_événementielles()
Application.EnableEvents = True
End Sub

Dans un second temps : revois ta procédure et assure toi
que cette ligne de code sera exécutée avant la fin de la
procédure : Application.EnableEvents = True

L'autre aspect de ta problématique, c'est la manière dont tu as écris
tes conditions, ta procédure pourrait ressemble à ceci... assure toi
que tes conditions sont bien respectées.

'----------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range

Worksheets("BDD").Columns("A:bz").AutoFit

If Intersect([be3:be500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([be3:be500], Target)
Select Case LCase(c.Value)
Case Is = "défavorable", "très défavorable"
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = 40

Case Is = "favorable", "très favorable"
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = 34

Case Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = xlNone
End Select
Next c
Application.EnableEvents = True
End If

If Intersect([an3:an500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([an3:an500], Target)
If c.Value <> "" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = 4
End If
Next c
Application.EnableEvents = True
End If
End Sub
'----------------------------------------------







Avatar
MichDenis
La procédure suivante fonctionne très bien !

Sauf que, comme c'est une procédure événementielle, celle-ci
s'active seulement au moment où tu sélectionnes une cellule
des plages mentionnées et selon les conditions posées, elle
colore ou non la ligne. Pour ce faire, il faut que le texte y soit
déjà.

Si tu désires que la couleur se modifie dès la modification du
contenu du texte, tu dois retenir plutôt l'événement
"Private Sub Worksheet_Change(ByVal Target As Range)"
Pour ce faire, tu n'as qu'à modifier la ligne de déclaration
de la procédure... le reste ne change pas.

'--------------------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range

Worksheets("Feuil2").Columns("A:bz").AutoFit

If Intersect([be3:be500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([be3:be500], Target)
Select Case LCase(c.Value)
Case Is = "défavorable"
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = 40

Case Is = "très défavorable"
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = 40

Case Is = "favorable", "très favorable"
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = 34

Case Else
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = xlNone
End Select
Next c
Application.EnableEvents = True


If Intersect([an3:an500], Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In Intersect([an3:an500], Target)
If c.Value <> "" Then _
Range(Cells(c.Row, "A"), Cells(c.Row, "BG")). _
Interior.ColorIndex = 4

Next c
Application.EnableEvents = True

End Sub
'--------------------------------------------------------
1 2