XL 2016 Excel - Conditionnal Formating VBA

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

  • Exemple_Contionnal formating.xlsm
    39.4 KB · Affichages: 6

Discussions similaires

Réponses
2
Affichages
655
C
Réponses
6
Affichages
2 K
Compte Supprimé 979
C