XL 2016 Résolu : Formatage de cellule

  • Initiateur de la discussion Initiateur de la discussion GClaire
  • Date de début Date de début

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 !

GClaire

XLDnaute Impliqué
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
 
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
 
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
 
- 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 worksheet_change
Réponses
29
Affichages
482
  • Question Question
Microsoft 365 colorer une plage
Réponses
2
Affichages
872
Réponses
22
Affichages
3 K
Réponses
2
Affichages
986
Retour