XL 2016 Excel - Conditionnal Formating VBA

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Solo_Wing75

XLDnaute Nouveau
Bonjour à tous,

J'espère que vous allez bien et vous remercie par avance pour votre aide.

J'ai tenter de mettre en oeuvre une formule VBA de mise en forme conditionnelle en fonction de certains critères mais si la macro s'enclenche bel et bien, rien ne se passe et je ne parviens pas à trouver l'erreur :

VB:
Public Sub ReapplyConditionalFormatting()
    
    ' Remove any existing conditional formatting
    With Sheets("2. Review Errors").Range("B13:D1048576")
        .FormatConditions.Delete
    End With
    
    ' Add conditional formatting
    With Sheets("2. Review Errors")
        With .Range("$C$13:$C$50")
            .Activate
            For Each Line In Range("$C$13:$C$50")
            ' Show green errors for any missing Node Name
            .FormatConditions.Add xlExpression, Formula1:= _
            IsEmpty(B13) = True
              
            .FormatConditions(1).Interior.ColorIndex = 35
            Next
            
        End With
        With .Range("$B$13:$B$1048576")
            .Activate
            
            ' Show blue errors for missing Node ID
            .FormatConditions.Add xlExpression, Formula1:="=AND(B13="""";OR(C13<>"""";D13<>""""))"
            .FormatConditions(1).Interior.ColorIndex = 37
            
            ' Show orange errors for duplicate Node ID
            .FormatConditions.AddUniqueValues
            .FormatConditions(2).DupeUnique = xlDuplicate
            .FormatConditions(2).Interior.ColorIndex = 40
        End With
        With .Range("$D$13:$D$1048576")
            .Activate
            
            ' Show purple errors for references to any Parent ID that does not exist in the list
            .FormatConditions.Add xlExpression, Formula1:="=AND(D13<>"""";ISERROR(MATCH(D13;$B$13:$B$1048576;0)))"
            .FormatConditions(1).Interior.ColorIndex = 39
            
            ' Highlight nodes with missing Parent Node ID
            .FormatConditions.Add xlExpression, Formula1:="=AND(OR(ISBLANK(B13)=FALSE;ISBLANK(D13)=FALSE);ISBLANK(D13))"
            .FormatConditions(2).Interior.ColorIndex = 38
            
            ' Show yellow errors for any node that refers to itself as its parent
            .FormatConditions.Add xlExpression, Formula1:="=AND(B13<>"""";D13<>"""";EXACT(D13;B13))"
            .FormatConditions(3).Interior.ColorIndex = 36

        End With
        
    End With
End Sub

Je vous joins également le fichier a titre d'exemple.

Une ame charitable aurait elle une idée de ce qui ne vas pas ?

Merci !
 

Pièces jointes

- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 colorer une plage
Réponses
2
Affichages
827
Réponses
10
Affichages
801
Réponses
2
Affichages
2 K
Réponses
0
Affichages
1 K
Réponses
3
Affichages
722
Réponses
7
Affichages
1 K
C
  • Question Question
Réponses
6
Affichages
2 K
Compte Supprimé 979
C
Réponses
12
Affichages
2 K
Réponses
22
Affichages
3 K
Retour