J'ai une table pivotante avec un élément caculé. Chaque fois que je change le paramètre dans le filtre principal du pivot, le formatage du texte revient par défaut.La macro VBA déclenchée par l'événement s'exécute mais ne s'exécute pas
Afin de ne pas formater la table à chaque fois, j'ai créé une macro, qui devrait formater le tableau croisé dynamique chaque fois que je mets une valeur dans la cellule D1. C2 est la cellule d'échantillon de format. Il semble que la macro s'exécute, mais ne s'exécute pas.
Pourriez-vous aider?
Le code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$d$1" Then
Application.EnableEvents = False
Range("C2").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=ORAZ(JEŻELI($B2=" 'OFERTA/TOTAL RYNEK'";1;0);JEŻELI(C2>1;1;0))"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16776961
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.399945066682943
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("C2").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=ORAZ(JEŻELI($B1=""OFERTA/TOTAL RYNEK"";1;0);JEŻELI(C1>1;1;0))"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16776961
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.399945066682943
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.Copy
Columns("C:N").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Application.EnableEvents = True
End If
End Sub
Pour commencer, vous avez besoin de 'If Target.Address =" $ D $ 1 "Then'. – SJR