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
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
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
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
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
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
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
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
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
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
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
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
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
>
>
>
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" <Michel69@discussions.microsoft.com> a écrit dans le message de groupe de
discussion : 1DA368B1-53F9-4294-BED3-11914C1ACD02@microsoft.com...
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
>
>
>
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
>
>
>
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
>
>
>
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" <Michel69@discussions.microsoft.com> a écrit dans le message de groupe de
discussion : 1DA368B1-53F9-4294-BED3-11914C1ACD02@microsoft.com...
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
>
>
>
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
>
>
>
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.
DanielBonjour à 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
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" <Michel69@discussions.microsoft.com> a écrit dans le message de
groupe de discussion :
1DA368B1-53F9-4294-BED3-11914C1ACD02@microsoft.com... 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
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.
DanielBonjour à 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
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
'----------------------------------------------
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
'----------------------------------------------
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
'----------------------------------------------