pb couleur onglets conditionnelle

kinarius

XLDnaute Nouveau
Bonjour à tous,
Apres avoir regarder sur le forum je ne trouve pas mon bonheur :(
En espérant trouver une personne compétente...

Je cherche à colorer des onglets en fonction de certaines valeur dans chaque page à l'ouverture du fichier ou pendant sa mise à jour. Chaque onglet sera identique.

J'ai ecris ceci mais apparement il doit y avoir une erreur :

Private Sub Workbook_open()
Dim WS_Count As Integer
Dim I As Integer

WS_Count = ActiveWorkbook.Worksheets.Count
For I = 1 To WS_Count

If ActiveSheet.Cells(37, 15) = "" And ActiveSheet.Cells(37, 10) > Now Then
ActiveSheet.Tab.ColorIndex = 6 'jaune

ElseIf ActiveSheet.Cells(37, 10) = "" Then
ActiveSheet.Tab.ColorIndex = 2 'gris

ElseIf ActiveSheet.Cells(37, 15) = "" And ActiveSheet.Cells(37, 10) < Now Then
ActiveSheet.Tab.ColorIndex = 3 'rouge

ElseIf ActiveSheet.Cells(59, 15) <> "" Then
ActiveSheet.Tab.ColorIndex = 10 'vert

End If
Next I

End Sub

Si quelqu'un peut m'aider.
Merci d'avance.
 

Pierrot93

XLDnaute Barbatruc
Re : pb couleur onglets conditionnelle

Re,

avec un bloc "with" :
Code:
Private Sub Workbook_open()
 Dim WS_Count As Integer
 Dim I As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
 For I = 1 To WS_Count
    With Worksheets(I)
       If .Cells(37, 15) = "" And .Cells(37, 10) > Now Then
            .Tab.ColorIndex = 6 'jaune
        ElseIf .Cells(37, 10) = "" Then
        .Tab.ColorIndex = 2 'gris
        ElseIf .Cells(37, 15) = "" And .Cells(37, 10) < Now Then
        .Tab.ColorIndex = 3 'rouge
        ElseIf .Cells(59, 15) <> "" Then
        .Tab.ColorIndex = 10 'vert
        End If
    End With
 Next I
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 694
Messages
2 091 039
Membres
104 735
dernier inscrit
sambetta