Macro excel mise en forme conditionnelle
Estelle
-
Gyrus Messages postés 3334 Date d'inscription Statut Membre Dernière intervention -
Gyrus Messages postés 3334 Date d'inscription Statut Membre Dernière intervention -
Bonjour!!
J'aimerais mettre des mises en forme conditionnelle, voici ce que ça a donné:
Windows("12-05-2016_extraction.xlsx").Activate
Range("P12").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=SI(($F2<=AUJOURDHUI()-10)*($N2=0);VRAI;FAUX)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -3880704
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Windows("Macro Extraction de Base.xlsm").Activate
Windows("12-05-2016_extraction.xlsx").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$AA2<AUJOURDHUI()"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Cells.FormatConditions.Delete
Range("A2:AB4000").Select
Range("T7").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$AA2<AUJOURDHUI()"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Windows("12-05-2016_extraction.xlsx").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AA2<=AUJOURDHUI()+7"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14286847
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Cells.FormatConditions.Delete
Range("A2:AB4000").Select
Range("P13").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AA2<=AUJOURDHUI()+7"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14286847
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("A2:AB4000").Select
Range("P13").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$AA13<AUJOURDHUI()"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = 0
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Seulement ça bug, certaines cases ne sont pas pris en compte et je n'arrive pas à interrompre une formule par rapport à une autre, ça ne veut pas le prendre dans la macro!
J'explique ce que je souhaite faire, il y a 3 formules conditionnelles que je souhaite appliquer, toutes s'applique à "=$A$2:$AB$4000";
1. =SI(($F2<=AUJOURDHUI()-10)*($N2=0);VRAI;FAUX)
mettre au format (texte en vert)
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
2. "=$AA2<AUJOURDHUI()
Mettre au format (remplissage en rouge)
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
3. =AA2<=AUJOURDHUI()+7 (mais prendre en compte d'abord le point 2!)
Mettre au format (remplissage jaune clair):
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14286847
.TintAndShade = 0
End With
Est-ce que quelqu'un peut m'aider?
Merci à vous!
J'aimerais mettre des mises en forme conditionnelle, voici ce que ça a donné:
Windows("12-05-2016_extraction.xlsx").Activate
Range("P12").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=SI(($F2<=AUJOURDHUI()-10)*($N2=0);VRAI;FAUX)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -3880704
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Windows("Macro Extraction de Base.xlsm").Activate
Windows("12-05-2016_extraction.xlsx").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$AA2<AUJOURDHUI()"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Cells.FormatConditions.Delete
Range("A2:AB4000").Select
Range("T7").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$AA2<AUJOURDHUI()"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Windows("12-05-2016_extraction.xlsx").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AA2<=AUJOURDHUI()+7"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14286847
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Cells.FormatConditions.Delete
Range("A2:AB4000").Select
Range("P13").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AA2<=AUJOURDHUI()+7"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14286847
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("A2:AB4000").Select
Range("P13").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$AA13<AUJOURDHUI()"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = 0
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Seulement ça bug, certaines cases ne sont pas pris en compte et je n'arrive pas à interrompre une formule par rapport à une autre, ça ne veut pas le prendre dans la macro!
J'explique ce que je souhaite faire, il y a 3 formules conditionnelles que je souhaite appliquer, toutes s'applique à "=$A$2:$AB$4000";
1. =SI(($F2<=AUJOURDHUI()-10)*($N2=0);VRAI;FAUX)
mettre au format (texte en vert)
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
2. "=$AA2<AUJOURDHUI()
Mettre au format (remplissage en rouge)
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
3. =AA2<=AUJOURDHUI()+7 (mais prendre en compte d'abord le point 2!)
Mettre au format (remplissage jaune clair):
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14286847
.TintAndShade = 0
End With
Est-ce que quelqu'un peut m'aider?
Merci à vous!
A voir également:
- Macro excel mise en forme conditionnelle
- Mise en forme conditionnelle excel - Guide
- Telecharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Mise en forme tableau word - Guide
- Liste déroulante excel - Guide
- Excel liste déroulante conditionnelle - Guide
1 réponse
Bonjour,
A tester :
A+
A tester :
Sub Test()
Cells.FormatConditions.Delete
With Workbooks("12-05-2016_extraction.xlsx").Worksheets("Feuil1").Range("A2:AB4000")
.FormatConditions.Add Type:=xlExpression, Formula1:="=ET($AA2<=AUJOURDHUI()+7;NON(ESTVIDE($AA2)))"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = 0
.Color = 14286847
.TintAndShade = 0
.PatternTintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
.FormatConditions.Add Type:=xlExpression, Formula1:="=ET($AA2<AUJOURDHUI();NON(ESTVIDE($AA2)))"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
.FormatConditions.Add Type:=xlExpression, Formula1:="=ET($F2<AUJOURDHUI()-10;$N2=0;NON(ESTVIDE($F2)))"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.Pattern = xlSolid
.PatternColorIndex = 0
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = True
End With
End Sub
A+
Merci de votre aide, cependant ça ne marche pas, ça me met:
"Erreur de compilation:
Référence incorrect ou non qualifiée"
Et ça sélectionne
.FormatConditions(.FormatConditions.Count).SetFirstPriority
As-tu adapté le nom de feuille ("Feuil1" dans l'exemple) ?
Profites-en pour déplacer la ligne Cells.FormatConditions.Delete
A+
Je ne peux pas spécifié
With Workbooks("12-05-2016_extraction.xlsx").Worksheets("Feuil1").Range("A2:AB4000")
Car le nom de fichier va changer toutes les semaines.
Une idée?
merci.
Avez-vous une autre solution?
merci.
Estelle