Couleur cellule

wrx924

XLDnaute Nouveau
bonsoir,
j'utilise une "moulinette" sous access2007 qui me permet d'analyser le
contenu d'un fichier excel.

le fichier Excel 2007 contient des règles de mise en forme conditionnelle.

je souhaiterai connaître le code vba qui me permet de connaître le code
couleur actif d'une cellule gérée par plusieurs règles de mise en forme
conditionnelle.

le code suivant xlRange.range("A1").interior.color me donne la valeur de la
couleur de la cellule sans application des règles de MeF conditionnelle

merci de votre aide
 

ROGER2327

XLDnaute Barbatruc
Re : Couleur cellule

Bonsoir wrx924
Le code :
Code:
[COLOR="DarkSlateGray"][B]Sub tata()
Dim x1#, x2#, x3#
   x1 = Range("A1").FormatConditions(1).Interior.Color
   x2 = Range("A1").FormatConditions(2).Interior.Color
   x3 = Range("A1").FormatConditions(3).Interior.Color
   MsgBox x1 & " / " & x2 & " / " & x3
End Sub[/B][/COLOR]
renvoie les paramètres de couleur de fond associé aux trois conditions associées à la mise en forme, pour autant qu'ils existent.
Avec Excel2007, j'ignore si ce code est correct. (Posez éventuellement le problème sur le forum spécial 2007...)​
ROGER2327
#3795


Vendredi 13 Gidouille 137 (SSaint Instintestins, conseillers intimes, SQ)
9 Messidor An CCXVIII
2010-W25-7T22:59:48Z
 

wrx924

XLDnaute Nouveau
Re : Couleur cellule

bonjour ROGER2327,

ok pour ce code
ma problématique est: quel code utiliser pour que vba retrouve la valeur couleur cellule de la règle active.
si aucune règle appliqué alors couleur est xlrange.range("A1").interiorcolor
si régle n°1 appliquée alors code est: xlrange.range ("A1").???????????.interiorcolor
si régle n°2 appliquée alors code est: xlrange.range ("A1").???????????.interiorcolor
etc.
merci
 

Cousinhub

XLDnaute Barbatruc
Re : Couleur cellule

Bonjour wrx,

Bonjour, Roger

Un code de Laurent Longre, gourou d'excel :

Code:
Sub FormatCondi()
'L Longre, mpfe
Dim FC As FormatCondition, F1, F2
Dim Cel As Range
Application.ScreenUpdating = False
For Each Cel In Cells.SpecialCells(xlCellTypeAllFormatConditions)
    Cel.Select
    For Each FC In Cel.FormatConditions
        If FC.Type = xlCellValue Then
            F1 = Evaluate(FC.Formula1)
            Select Case FC.Operator
                Case xlBetween: If Cel >= F1 _
                    And Cel <= Evaluate(FC.Formula2) Then Exit For
                Case xlEqual: If Cel = F1 Then Exit For
                Case xlGreater: If Cel > F1 Then Exit For
                Case xlGreaterEqual: If Cel >= F1 Then Exit For
                Case xlLess: If Cel < F1 Then Exit For
                Case xlLessEqual: If Cel <= F1 Then Exit For
                Case xlNotBetween: If Cel < F1 _
                    Or Cel > Evaluate(FC.Formula2) Then Exit For
                Case xlNotEqual: If Cel <> F1 Then Exit For
            End Select
        Else
            If Evaluate(FC.Formula1) Then Exit For
        End If
    Next FC
    If Not FC Is Nothing Then
        MsgBox "Cellule : " & Cel.Address & Chr(10) & "Couleur : " & FC.Interior.ColorIndex
    Else
        MsgBox Cel.Interior.ColorIndex
    End If
Next Cel
End Sub

Bonne journée
 

Discussions similaires

Statistiques des forums

Discussions
312 412
Messages
2 088 181
Membres
103 755
dernier inscrit
Nicolas TULENGE