Autres Arrêt macro avec InputBox - Message "Incompatibilité de type

tamatave33

XLDnaute Occasionnel
Bonjour le forum,

J'ai une macro qui me permet d'effacer les valeurs des cellules d'un tableau lorsque celles-ci sont égales à la valeur saisie dans une InputBox.
Tout marche bien si je saisi une valeur, mais si je clique sur le bouton Annuler de l'inputbox ou si je ne saisi pas de valeur, j'ai un message d'erreur : "Incompatilité de type".

Voici le code :
VB:
Sub Nettoyer_la_grille()

    Dim mois As String, i As Integer, j As Integer
    mois = Application.InputBox("Quel mois (en chiffre) veux-tu effacer ?")
    If mois = 0 Or "" Then Exit Sub
    If mois = False Then Exit Sub
    
    With Sheets("Partenaires")

        Unprotect
    
        Range("D4") = mois

        For i = 130 To 5 Step -1
        For j = 130 To 5 Step -1
            If Cells(i, j) = mois Then Cells(i, j).ClearContents
        Next j
        Next i

        Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True

    End With

End Sub

Merci pour votre aide.
 

mapomme

XLDnaute Barbatruc
Supporter XLD
Bonsoir @tamatave33,

Essayez:
VB:
Sub Nettoyer_la_grille()
Dim mois, i As Integer, j As Integer
  mois = Application.InputBox("Quel mois (en chiffre) veux-tu effacer ?")
  If mois = 0 Or mois = "" Or Not IsNumeric(mois) Then Exit Sub
  mois = Int(mois)
  If mois < 1 Or mois > 12 Then Exit Sub
  MsgBox mois   'pour le test
  With Sheets("Partenaires")
    '....... la suite du code
  End With
End Sub
 
Dernière édition:

Discussions similaires

Réponses
8
Affichages
448