Run-time error '91': Object variable or With block variable not

Résolu
Ch1ken Messages postés 59 Statut Membre -  
Ch1ken Messages postés 59 Statut Membre -
Bonjour,

Je débute en VBA et j'ai un erreur qui me pose quelques soucis. Il s'agit de l'erreur "Run-time error '91': Object variable or With block variable not ". Ce message d'erreur s'affiche mais ma macro s'effectue pourtant convenablement, il doit s'agit donc d'une petit erreur de déclaration ou autre ?

Voici mon code :

Sub oldMarks1()
ActiveSheet.Unprotect
For Each cell In Range("B3", "M9")
If cell.Interior.Color = RGB(51, 153, 255) Then
cell.Interior.Color = RGB(200, 173, 127)
cell.AddComment "Dernière validation par X"
End If
Next
For Each cell In Range("B3", "M9")
If cell.Comment.Text Like "Dernière validation par Y" Then
cell.Interior.Color = RGB(255, 255, 255)
cell.ClearComments
End If
Next
'ActiveSheet.Protect
End Sub

Sub oldMarks2()
ActiveSheet.Unprotect
For Each cell In Range("B3", "M9")
If cell.Interior.Color = RGB(51, 153, 255) Then
cell.Interior.Color = RGB(200, 173, 127)
cell.AddComment "Dernière validation par Y"
End If
Next
For Each cell In Range("B3", "M9")
If cell.Comment.Text Like "Dernière validation par X" Then
cell.Interior.Color = RGB(255, 255, 255)
cell.ClearComments
End If
Next
'ActiveSheet.Protect
End Sub


Ce code a pour but de modifier la couleur de certaines cellules en fonction de validation d'autres utilisateurs via 2 boutons.

Merci d'avance pour votre aide

1 réponse

  1. f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   1 717
     
    Bonjour,

    Pour tester le texte commentaire, il faut deja tester s'il y a un commentaire

    Sub oldMarks1()
        Dim Cel_Comment As Comment
        
       ActiveSheet.Unprotect
        For Each Cell In Range("B3", "M9")
            If Cell.Interior.Color = RGB(51, 153, 255) Then
                Cell.Interior.Color = RGB(200, 173, 127)
                Cell.AddComment "Dernière validation par X"
            End If
        Next
        For Each Cell In Range("B3", "M9")
            Ligne = 1
            Set Cel_Comment = Cell.Comment
            If Not Cel_Comment Is Nothing Then 'test s'il y a un commentaire dans la cellule
                 If Cell.Comment.Text = "Dernière validation par Y" Then
                    Cell.Interior.Color = RGB(255, 255, 255)
                    Cell.ClearComments
                End If
            End If
        Next
        'ActiveSheet.Protect
    End Sub


    faites de meme pour la deuxieme procedure
    2
    1. Ch1ken Messages postés 59 Statut Membre 6
       
      Marche tip-top merci je vais checker ca
      0