Boucle infinie

Bonjour,

Voici ma macro qui est en fait une boucle infinie et je ne comprends pas pourquoi :

Sub AjoutLigne()
    nb = 20
    cpr = 0
    i = InputBox(Prompt:="Nombre de produits à entrer  dans le formulaire")
    If i <> "" Then
            If IsNumeric(i) Then
                If cpr < i Then
                    While cpr <> i
                        MsgBox ("I vaut : " & i)
                        MsgBox ("cpr vaut : " & cpr)
                        Range("E" & nb & ":H" & nb).Select
                        Selection.Copy
                        Range("E" & (nb + 1) & ":H" & (nb + 1)).Select
                        Selection.PasteSpecial Paste:=xlFormats
                        cpr = cpr + 1
                        nb = nb + 1
                    Wend
                End If
            Else
                MsgBox ("Veuillez entrez un nombre s'il vous plaît.")
            End If
        End If
End Sub 

Bonjour,

Essaie comme cela

Option Explicit
Sub AjoutLigne()
Dim Max As String
Dim i As Long, cpr As Long, nb As Long
        nb = 20
        cpr = 0
        Max = InputBox(Prompt:="Nombre de produits à entrer  dans le formulaire")
        If Max <> "" Then
            If IsNumeric(Max) Then
                i = CLng(Max)
                If cpr < i Then
                    While cpr <> i
                        Range("E" & nb & ":H" & nb).Copy
                        Range("E" & (nb + 1) & ":H" & (nb + 1)).PasteSpecial Paste:=xlFormats
                        cpr = cpr + 1
                        nb = nb + 1
                    Wend
                End If
            Else
                MsgBox ("Veuillez entrez un nombre s'il vous plaît.")
            End If
        End If
        Application.CutCopyMode = False
End Sub

A+

Je te remercie c'est parfait !

Rechercher des sujets similaires à "boucle infinie"