Excel - Incompatibilité de type

Résolu/Fermé
tbeghain Messages postés 58 Date d'inscription mercredi 31 mars 2004 Statut Membre Dernière intervention 22 février 2021 - 19 janv. 2011 à 16:03
tbeghain Messages postés 58 Date d'inscription mercredi 31 mars 2004 Statut Membre Dernière intervention 22 février 2021 - 19 janv. 2011 à 16:27
Bonjour,

Dans une feuille Excel, je voulais colorier des cellules avec des couleurs différentes selon la valeur du ciontenu de ces cellules. j'ai trouvé sur Internet un bout de code que j'ai adapté et qui remplit très bien cette fonction.
Seulement voilà, lorsque je veux copier, supprimer, ou insérer une ligne, j'ai un message :
'Erreur d'exécution 13 : Incompatibilité de type', et je ne comprends pas pourquoi. Voilà la bout de code en question que j'ai inséré dans ma feuille Excel :

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "Pas d'info" Then
Target.Interior.ColorIndex = 35
End If
If Target.Value = "En attente" Then
Target.Interior.ColorIndex = 34
End If
If Target.Value = "En cours" Then
Target.Interior.ColorIndex = 36
End If
If Target.Value = "Ne fonctionne pas" Then
Target.Interior.ColorIndex = 3
End If
If Target.Value = "Annulé" Then
Target.Interior.ColorIndex = 40
End If
If Target.Value = "Terminé" Then
Target.Interior.ColorIndex = 4
End If
End Sub

Est-ce qu'il faut mettre autre chose ?
Merci





A voir également:

2 réponses

eriiic Messages postés 24571 Date d'inscription mardi 11 septembre 2007 Statut Contributeur Dernière intervention 8 mai 2024 7 216
19 janv. 2011 à 16:22
Bonjour,

Ton code modifié :
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Target Is Nothing And Target.Cells.Count = 1 Then
        Select Case Target.Value
        Case "Pas d'info"
            Target.Interior.ColorIndex = 35
        Case "En attente"
            Target.Interior.ColorIndex = 34
        Case "En cours"
            Target.Interior.ColorIndex = 36
        Case "Ne fonctionne pas"
            Target.Interior.ColorIndex = 3
        Case "Annulé"
            Target.Interior.ColorIndex = 40
        Case "Terminé"
            Target.Interior.ColorIndex = 4
        End Select
    End If
End Sub


eric
0
tbeghain Messages postés 58 Date d'inscription mercredi 31 mars 2004 Statut Membre Dernière intervention 22 février 2021 3
19 janv. 2011 à 16:27
Merci beaucoup, ça va beaucoup mieux.
0