XL 2016 Résolu : Formatage de cellule

GClaire

XLDnaute Occasionnel
Supporter XLD
Hello.

J'utilise ce code pour coloriser La cellule E de la dernière ligne.

VB:
        .Range("E" & DerLgn).Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent3
        .TintAndShade = 0.599993896298105
        .PatternTintAndShade = 0
    End With

Afin de ne pas multiplier ce même code, que dois-je mettre si par exemple

1) Je veux le faire sur des cellules cote a cote E;F;G

2) ou éloigne E;G;I

J'ai essayé différantes chose mais en vain.

Merci

Cordialement, G'Claire
 

Dranreb

XLDnaute Barbatruc
Bonsoir.
VB:
' 1) — With .[E:G].Rows(DerLgn)).Interior
' 2) — :
   With Intersect(.[E:E,G:G,I:I], .Rows(DerLgn)).Interior
' Dans les deux cas :
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent3
        .TintAndShade = 0.599993896298105
        .PatternTintAndShade = 0
    End With
 

GClaire

XLDnaute Occasionnel
Supporter XLD
Hello.

Bon j'ai trouvé mon erreur un ".rows", mal placé.

Alors un truc que je ne comprend.

Si je met cette fonction dans un module, avec ce code :

Et la lance avec

Call Mdl_FormatNouveauMouvement

VB:
Sub Mdl_FormatNouveauMouvement()
'
'
'

'
With Sheets(strNomFeuille)

    With .[A:P].Rows(DerLgn).Borders(xlEdgeLeft)
        .LineStyle = xlDouble
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThick
    End With
    With .[A:P].Rows(DerLgn).Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
   
    With .[A:P].Rows(DerLgn).Borders(xlEdgeRight)
        .LineStyle = xlDouble
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThick
    End With
    With .[A:P].Rows(DerLgn).Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
   
    With .[A:P].Rows(DerLgn)
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With


    With .[A:D].Rows(DerLgn)
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
   
    With .[E:P].Rows(DerLgn)
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
   
    With .Range("E" & DerLgn).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent3
        .TintAndShade = 0.599993896298105
        .PatternTintAndShade = 0
    End With
   
    With Intersect(.[F:F, H:H, J:J], .Rows(DerLgn)).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark2
        .TintAndShade = -9.99786370433668E-02
        .PatternTintAndShade = 0
    End With
   
    With Intersect(.[G:G, I:I, K:K], .Rows(DerLgn)).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorLight2
        .TintAndShade = 0.799981688894314
        .PatternTintAndShade = 0
    End With
   
    With .Range("L" & DerLgn).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark2
        .TintAndShade = -0.249977111117893
        .PatternTintAndShade = 0
    End With
   
    With .[M:N].Rows(DerLgn).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorLight2
        .TintAndShade = 0.599993896298105
        .PatternTintAndShade = 0
    End With
   
    With .Range("O" & DerLgn).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent4
        .TintAndShade = 0.799981688894314
        .PatternTintAndShade = 0
    End With
   
    With .Range("P" & DerLgn).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.799981688894314
        .PatternTintAndShade = 0
    End With
End With
End Sub

Cela devrait me formater dans la feuille du Nom contenu dans la variable (Celle-ci est déclaré en Public dans un module ou il y a plein de variable), même si je suis dans une autre feuille non?

Et bien suivant dans quelle feuille je suis, cela me format dans la feuille sélectionnée.

Ou ai-je fait une erreur?

Merci, G'Claire
 

Statistiques des forums

Discussions
312 154
Messages
2 085 807
Membres
102 986
dernier inscrit
nonoblez