Couleur de police en même temps que le fond de cellule

isa44

XLDnaute Occasionnel
Bonjour , j'ai un code pour une couleur de fond de cellule en fonction de son contenu.
Je me demande s'il y a aussi une possibilité de changer la police à la suite de ce code ?
J'ai fait des essais " code en bleu " sans succès :

HTML:
Sub fondcellule()
Dim celCol, oCol As Range
For Each oCol In Range("C31:IU50").Cells
Select Case oCol.Value
Case "R": celCol = 4
Case "M": celCol = 44
Case "S": celCol = 41
Case "4": celCol = 3
Case "2": celCol = 46

Case "MC": celCol = 44
[COLOR="#000080"]Case "MC": celFontCol = 3
Case "MC": celFontStyle = "Gras"
Case "MC": celUnderline = xlUnderlineStyleSingle[/COLOR]

Case "SC": celCol = 41
[COLOR="#000080"]Case "SC": celFontCol = 3
Case "SC": celFontStyle = "Gras"
Case "SC": celUnderline = xlUnderlineStyleSingle[/COLOR]


Case Else: celCol = xlNone
End Select
oCol.Interior.ColorIndex = celCol
Next oCol
End Sub
 
Dernière édition:

DoubleZero

XLDnaute Barbatruc
Re : Couleur de police en même temps que le fond de cellule

Bonjour, isa44, le Forum,

Peut-être ainsi :

Code:
Option Explicit
Sub MFC()
    Dim c As Range
    Application.ScreenUpdating = False
    For Each c In Range("C1:IU50").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants, 23)
        Select Case c.Value
        Case Is = "R": c.Interior.ColorIndex = 4
        Case Is = "M": c.Interior.ColorIndex = 44
        Case Is = "S": c.Interior.ColorIndex = 41
        Case Is = 4: c.Interior.ColorIndex = 3
        Case Is = 2: c.Interior.ColorIndex = 46
        Case Is = "MC": c.Interior.ColorIndex = 44: c.Font.Bold = True
        Case Is = "SC": c.Interior.ColorIndex = 41: c.Font.Bold = True
        Case Else: c.Interior.ColorIndex = xlNone: c.Font.Bold = False
        End Select
    Next
    Application.ScreenUpdating = True
End Sub

A bientôt :)
 

isa44

XLDnaute Occasionnel
Re : Couleur de police en même temps que le fond de cellule

Super ça marche , juste une correction:
Si par exemple je tape 4 dans une cellule la MFC fonctionne bien , mais si je supprime le 4 le fond de cellule reste.
Si la cellule est vide je ne voudrais pas de couleur de fond.
 

DoubleZero

XLDnaute Barbatruc
Re : Couleur de police en même temps que le fond de cellule

Re-bonjour,

Dans ce cas, peut-être comme ceci :

Code:
Option Explicit
Sub MFC_V2()
    Dim c As Range
    Application.ScreenUpdating = False
    With Range("C1:IU50"): .Interior.ColorIndex = xlNone: .Font.Bold = False: End With
    For Each c In Range("C1:IU50").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants, 23)
        Select Case c.Value
        Case Is = "": c.Interior.ColorIndex = xlNone: c.Font.Bold = False
        Case Is = "R": c.Interior.ColorIndex = 4
        Case Is = "M": c.Interior.ColorIndex = 44
        Case Is = "S": c.Interior.ColorIndex = 41
        Case Is = 4: c.Interior.ColorIndex = 3
        Case Is = 2: c.Interior.ColorIndex = 46
        Case Is = "MC": c.Interior.ColorIndex = 44: c.Font.Bold = True
        Case Is = "SC": c.Interior.ColorIndex = 41: c.Font.Bold = True
        Case Else: c.Interior.ColorIndex = xlNone: c.Font.Bold = False
        End Select
    Next
    Application.ScreenUpdating = True
End Sub

A bientôt :)
 

Discussions similaires

Statistiques des forums

Discussions
311 725
Messages
2 081 947
Membres
101 849
dernier inscrit
florentMIG