XL 2013 mise en forme conditionnelle sur plusieurs onglets

Dombal

XLDnaute Junior
Bonjour,

Je coince sur une macro et je ne trouve pas la solution donc j'en appelle à vous pour m'aider !

J'ai créé une macro avec une mise en forme conditionnelle qui s'applique sur un onglet (tableau croisé dynamique) qui regroupe l'ensemble des infos qui viennent d'un rapport et reprend l'ensemble des personnes de la société. J'aimerai que lors de la mise à jour, le mise en forme conditionnelle s'applique également sur tous les autres onglets qui vont être créés, en sachant que chaque nouvel onglet sera un tableau croisé dynamique qui est créé pour chaque personne de la société.

Je m'explique... quand je mets à jour la macro va tout d'abord supprimer les onglets existants, puis va aller chercher dans un onglet annexe une liste de personnes. Elle va ensuite recréer un onglet par personne, mais la mise en forme conditionnelle ne s'applique pas sur tous les nouveaux onglets.

Ci-dessous la macro actuelle : en rouge la mise en forme conditionnelle sous forme de recorded macro et qu'il faudrait pouvoir appliquer aux autres onglets.


Sub Refresh()

Dim xWs As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In Application.ActiveWorkbook.Worksheets
If xWs.Name <> "Welcome" And xWs.Name <> "Event" And xWs.Name <> "data" And xWs.Name <> "dataad" Then
xWs.Delete
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
ThisWorkbook.RefreshAll
Sheets("Event").Select
Range("B11").Select
ActiveSheet.PivotTables("PivotTable1").ShowPages PageField:="Event Mgr"
Sheets("Event").Select
Sheets("Event").Move Before:=Sheets(2)
Dim MySheet As Worksheet
Dim MyPivot As PivotTable
Dim slCaches As SlicerCaches
Dim slCache As SlicerCache
Set slCaches = ThisWorkbook.SlicerCaches
For Each slCache In slCaches
For Each MySheet In ActiveWorkbook.Worksheets
For Each MyPivot In MySheet.PivotTables
slCache.PivotTables.AddPivotTable MyPivot
Next MyPivot
Next MySheet
Next slCache
Sheets("Event").Select

Range("B12").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="=$B$11*95%"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions(1).ScopeType = xlFieldsScope
Range("B11").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="=$B$12"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("B13").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="=$B$12"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions(1).ScopeType = xlFieldsScope

End Sub


Je vous remercie d'avance de votre aide ! Bonne journée
 

Statistiques des forums

Discussions
311 725
Messages
2 081 941
Membres
101 848
dernier inscrit
Djigbenou