Comprotement d'une message box anormale

coucou qui purrait jeter un un regard ,

dans mon code tous fonctionne (comme je debute les conditions déclarées sont long mais elle marche pour la reduction du code je verais après) sauf que quand la mgsbox qui demande si on veut enregistrer apparait que l'on clique oui ou que l'on clique non elle eregistre toujours le contenue de facture dans le base correspondante pourquoi je ne trouve pas !

Sub enregistrer()
Dim xnumero As Integer
Fac_Dev = Cells(1, 9)
Fac_Num = Cells(1, 10)
Xonglet = Cells(1, 17)
If Cells(1, 10) = "" Then  'numero de doc
        MsgBox ("coisir un type de documment")
        Exit Sub
    End If
If Cells(41, 10) = "0" Then  'facture vide
        MsgBox ("votre facture est vide")
        Exit Sub
    End If

If Cells(45, 4) = "" Then  'reglement
       reponse = MsgBox("saisisé le mode de reglement", vbYesNo)
       If reponse = vbYes Then Exit Sub

End If
Application.ScreenUpdating = False 'enregistrement du document dans la base
reponse = MsgBox("Voulez-vous enregistrer :" & Fac_Dev & Fac_Num & " ?", vbYesNo)
            If reponse = vbYes Then
            ActiveSheet.PageSetup.PrintArea = "$A$1:J53"
            If reponse = vbNo Then Exit Sub

     End If

With Sheets(Xonglet) 'selection des données a enregistrer
    x = .Range("A65536").End(xlUp).Row
    xnumero = Right(.Cells(x, 1), 5)
End With
NFacture = Right(Cells(1, 10), 5) - 1

If NFacture = xnumero Then
    With Sheets(Xonglet)

        i = .Range("A65536").End(3)(2).Row
        .Cells(i, 1) = Sheets("facture").Range("J1") ' Numéro Devis ou Facture ou commande
        .Cells(i, 2) = Range("nom")
        .Cells(i, 3) = Range("prenom")
        .Cells(i, 4) = Range("adresse")
        .Cells(i, 5) = Range("code_postal")
        .Cells(i, 6) = Range("ville")
        .Cells(i, 7) = Range("date")
        .Cells(i, 8) = Range("client")
        .Cells(i, 9) = Range("B15")
        .Cells(i, 10) = Range("h15")
        .Cells(i, 11) = Range("I15")
        .Cells(i, 12) = Range("J15")
        .Cells(i, 13) = Range("B16")
        .Cells(i, 14) = Range("h16")
        .Cells(i, 15) = Range("I16")
        .Cells(i, 16) = Range("J16")
        .Cells(i, 17) = Range("B17")
        .Cells(i, 18) = Range("h17")
        .Cells(i, 19) = Range("I17")
        .Cells(i, 20) = Range("J17")
        .Cells(i, 21) = Range("B18")
        .Cells(i, 22) = Range("h18")
        .Cells(i, 23) = Range("I18")
        .Cells(i, 24) = Range("J18")
        .Cells(i, 25) = Range("B19")
        .Cells(i, 26) = Range("h19")
        .Cells(i, 27) = Range("I19")
        .Cells(i, 28) = Range("J19")
        .Cells(i, 29) = Range("B20")
        .Cells(i, 30) = Range("h20")
        .Cells(i, 31) = Range("I20")
        .Cells(i, 32) = Range("J20")
        .Cells(i, 33) = Range("B21")
        .Cells(i, 34) = Range("h21")
        .Cells(i, 35) = Range("I21")
        .Cells(i, 36) = Range("J21")
        .Cells(i, 37) = Range("B22")
        .Cells(i, 38) = Range("h22")
        .Cells(i, 39) = Range("I22")
        .Cells(i, 40) = Range("J22")
        .Cells(i, 41) = Range("B23")
        .Cells(i, 42) = Range("h23")
        .Cells(i, 43) = Range("I23")
        .Cells(i, 44) = Range("J23")
        .Cells(i, 45) = Range("B24")
        .Cells(i, 46) = Range("h24")
        .Cells(i, 47) = Range("I24")
        .Cells(i, 48) = Range("J24")
        .Cells(i, 49) = Range("B25")
        .Cells(i, 50) = Range("h25")
        .Cells(i, 51) = Range("I25")
        .Cells(i, 52) = Range("J25")
        .Cells(i, 53) = Range("B26")
        .Cells(i, 54) = Range("h26")
        .Cells(i, 55) = Range("I26")
        .Cells(i, 56) = Range("J26")
        .Cells(i, 57) = Range("B27")
        .Cells(i, 58) = Range("h27")
        .Cells(i, 59) = Range("I27")
        .Cells(i, 60) = Range("J27")
        .Cells(i, 61) = Range("B28")
        .Cells(i, 62) = Range("h28")
        .Cells(i, 63) = Range("I28")
        .Cells(i, 64) = Range("J28")
        .Cells(i, 65) = Range("B29")
        .Cells(i, 66) = Range("h29")
        .Cells(i, 67) = Range("I29")
        .Cells(i, 68) = Range("J29")
        .Cells(i, 69) = Range("B30")
        .Cells(i, 70) = Range("h30")
        .Cells(i, 71) = Range("I30")
        .Cells(i, 72) = Range("J30")
        .Cells(i, 73) = Range("B31")
        .Cells(i, 74) = Range("h31")
        .Cells(i, 75) = Range("I31")
        .Cells(i, 76) = Range("J31")
        .Cells(i, 77) = Range("B32")
        .Cells(i, 78) = Range("h32")
        .Cells(i, 79) = Range("I32")
        .Cells(i, 80) = Range("J32")
        .Cells(i, 81) = Range("B33")
        .Cells(i, 82) = Range("h33")
        .Cells(i, 83) = Range("I33")
        .Cells(i, 84) = Range("J33")
        .Cells(i, 85) = Range("B34")
        .Cells(i, 86) = Range("h34")
        .Cells(i, 87) = Range("I34")
        .Cells(i, 88) = Range("J34")
        .Cells(i, 89) = Range("B35")
        .Cells(i, 90) = Range("h35")
        .Cells(i, 91) = Range("I35")
        .Cells(i, 92) = Range("J35")
        .Cells(i, 93) = Range("B36")
        .Cells(i, 94) = Range("h36")
        .Cells(i, 95) = Range("I36")
        .Cells(i, 96) = Range("J36")
        .Cells(i, 97) = Range("B37")
        .Cells(i, 98) = Range("h37")
        .Cells(i, 99) = Range("I37")
        .Cells(i, 100) = Range("J37")
        .Cells(i, 101) = Range("B38")
        .Cells(i, 102) = Range("h38")
        .Cells(i, 103) = Range("I38")
        .Cells(i, 104) = Range("J38")
        .Cells(i, 105) = Range("B39")
        .Cells(i, 106) = Range("h39")
        .Cells(i, 107) = Range("I39")
        .Cells(i, 108) = Range("J39")
        .Cells(i, 109) = Range("B40")
        .Cells(i, 110) = Range("h40")
        .Cells(i, 111) = Range("I40")
        .Cells(i, 112) = Range("J40")
        .Cells(i, 113) = Range("total")
        .Cells(i, 114) = Range("acompte")
        .Cells(i, 115) = Range("net_a_payer")
        .Cells(i, 116) = Range("reglement")
        .Cells(i, 117) = Range("mail")
        .Cells(i, 118) = Range("G12")

 End With 'document a imprimer
   reponse = MsgBox("Voulez-vous imprimer :" & Fac_Dev & Fac_Num & " ?", vbYesNo)
            If reponse = vbYes Then
            ActiveSheet.PageSetup.PrintArea = "$B$1:J53"
            ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
            If reponse = vbNo Then Exit Sub
            End If
 'effacemment du document
    Range("B15:I40").ClearContents
    Range("Q8").ClearContents
    Range("R8").ClearContents
    Range("J43").ClearContents
    Range("D45").ClearContents
    Range("Q1").ClearContents
    Range("J1").ClearContents
    End If
Application.ScreenUpdating = True  ' retour a ma facture
Sheets("facture").Select
End Sub

et en prime mon ficher qui fonctione comme suit ( 1 type de doc, 2 client , 3 on replie au moin une ligne de champs puis on enregistre et c'est la que le comportement est pas au top car il sauve quoi qu'il arrive et surtout quoi qu'on lui dise.

merci pour vos lumières

cedcyr

Bonsoir,

Essaie comme cela

Sub enregistrer()
Dim xnumero As Integer
    Fac_Dev = Cells(1, 9)
    Fac_Num = Cells(1, 10)
    Xonglet = Cells(1, 17)

    If Cells(1, 10) = "" Then  'numero de doc
        MsgBox ("choisir un type de documment")
        Exit Sub
    End If

    If Cells(41, 10) = "0" Then  'facture vide
        MsgBox ("votre facture est vide")
        Exit Sub
    End If

    If Cells(45, 4) = "" Then  'reglement
       reponse = MsgBox("saisisé le mode de reglement", vbYesNo)
       If reponse = vbYes Then Exit Sub
    End If

    Application.ScreenUpdating = False 'enregistrement du document dans la base
    reponse = MsgBox("Voulez-vous enregistrer :" & Fac_Dev & Fac_Num & " ?", vbYesNo)
    If reponse = vbNo Then Exit Sub

    With Sheets(Xonglet) 'selection des données a enregistrer
        x = .Range("A65536").End(xlUp).Row
        xnumero = Right(.Cells(x, 1), 5)
    End With

    NFacture = Right(Cells(1, 10), 5) - 1
    If NFacture = xnumero Then
        With Sheets(Xonglet)
            i = .Range("A65536").End(3)(2).Row
            .Cells(i, 1) = Sheets("facture").Range("J1") ' Numéro Devis ou Facture ou commande
            .Cells(i, 2) = Range("nom")
            .Cells(i, 3) = Range("prenom")
            .Cells(i, 4) = Range("adresse")
            .Cells(i, 5) = Range("code_postal")
            .Cells(i, 6) = Range("ville")
            .Cells(i, 7) = Range("date")
            .Cells(i, 8) = Range("client")
            .Cells(i, 9) = Range("B15")
            .Cells(i, 10) = Range("h15")
            .Cells(i, 11) = Range("I15")
            .Cells(i, 12) = Range("J15")
            .Cells(i, 13) = Range("B16")
            .Cells(i, 14) = Range("h16")
            .Cells(i, 15) = Range("I16")
            .Cells(i, 16) = Range("J16")
            .Cells(i, 17) = Range("B17")
            .Cells(i, 18) = Range("h17")
            .Cells(i, 19) = Range("I17")
            .Cells(i, 20) = Range("J17")
            .Cells(i, 21) = Range("B18")
            .Cells(i, 22) = Range("h18")
            .Cells(i, 23) = Range("I18")
            .Cells(i, 24) = Range("J18")
            .Cells(i, 25) = Range("B19")
            .Cells(i, 26) = Range("h19")
            .Cells(i, 27) = Range("I19")
            .Cells(i, 28) = Range("J19")
            .Cells(i, 29) = Range("B20")
            .Cells(i, 30) = Range("h20")
            .Cells(i, 31) = Range("I20")
            .Cells(i, 32) = Range("J20")
            .Cells(i, 33) = Range("B21")
            .Cells(i, 34) = Range("h21")
            .Cells(i, 35) = Range("I21")
            .Cells(i, 36) = Range("J21")
            .Cells(i, 37) = Range("B22")
            .Cells(i, 38) = Range("h22")
            .Cells(i, 39) = Range("I22")
            .Cells(i, 40) = Range("J22")
            .Cells(i, 41) = Range("B23")
            .Cells(i, 42) = Range("h23")
            .Cells(i, 43) = Range("I23")
            .Cells(i, 44) = Range("J23")
            .Cells(i, 45) = Range("B24")
            .Cells(i, 46) = Range("h24")
            .Cells(i, 47) = Range("I24")
            .Cells(i, 48) = Range("J24")
            .Cells(i, 49) = Range("B25")
            .Cells(i, 50) = Range("h25")
            .Cells(i, 51) = Range("I25")
            .Cells(i, 52) = Range("J25")
            .Cells(i, 53) = Range("B26")
            .Cells(i, 54) = Range("h26")
            .Cells(i, 55) = Range("I26")
            .Cells(i, 56) = Range("J26")
            .Cells(i, 57) = Range("B27")
            .Cells(i, 58) = Range("h27")
            .Cells(i, 59) = Range("I27")
            .Cells(i, 60) = Range("J27")
            .Cells(i, 61) = Range("B28")
            .Cells(i, 62) = Range("h28")
            .Cells(i, 63) = Range("I28")
            .Cells(i, 64) = Range("J28")
            .Cells(i, 65) = Range("B29")
            .Cells(i, 66) = Range("h29")
            .Cells(i, 67) = Range("I29")
            .Cells(i, 68) = Range("J29")
            .Cells(i, 69) = Range("B30")
            .Cells(i, 70) = Range("h30")
            .Cells(i, 71) = Range("I30")
            .Cells(i, 72) = Range("J30")
            .Cells(i, 73) = Range("B31")
            .Cells(i, 74) = Range("h31")
            .Cells(i, 75) = Range("I31")
            .Cells(i, 76) = Range("J31")
            .Cells(i, 77) = Range("B32")
            .Cells(i, 78) = Range("h32")
            .Cells(i, 79) = Range("I32")
            .Cells(i, 80) = Range("J32")
            .Cells(i, 81) = Range("B33")
            .Cells(i, 82) = Range("h33")
            .Cells(i, 83) = Range("I33")
            .Cells(i, 84) = Range("J33")
            .Cells(i, 85) = Range("B34")
            .Cells(i, 86) = Range("h34")
            .Cells(i, 87) = Range("I34")
            .Cells(i, 88) = Range("J34")
            .Cells(i, 89) = Range("B35")
            .Cells(i, 90) = Range("h35")
            .Cells(i, 91) = Range("I35")
            .Cells(i, 92) = Range("J35")
            .Cells(i, 93) = Range("B36")
            .Cells(i, 94) = Range("h36")
            .Cells(i, 95) = Range("I36")
            .Cells(i, 96) = Range("J36")
            .Cells(i, 97) = Range("B37")
            .Cells(i, 98) = Range("h37")
            .Cells(i, 99) = Range("I37")
            .Cells(i, 100) = Range("J37")
            .Cells(i, 101) = Range("B38")
            .Cells(i, 102) = Range("h38")
            .Cells(i, 103) = Range("I38")
            .Cells(i, 104) = Range("J38")
            .Cells(i, 105) = Range("B39")
            .Cells(i, 106) = Range("h39")
            .Cells(i, 107) = Range("I39")
            .Cells(i, 108) = Range("J39")
            .Cells(i, 109) = Range("B40")
            .Cells(i, 110) = Range("h40")
            .Cells(i, 111) = Range("I40")
            .Cells(i, 112) = Range("J40")
            .Cells(i, 113) = Range("total")
            .Cells(i, 114) = Range("acompte")
            .Cells(i, 115) = Range("net_a_payer")
            .Cells(i, 116) = Range("reglement")
            .Cells(i, 117) = Range("mail")
            .Cells(i, 118) = Range("G12")
        End With

        'document a imprimer
        reponse = MsgBox("Voulez-vous imprimer :" & Fac_Dev & Fac_Num & " ?", vbYesNo)
        If reponse = vbYes Then
            ActiveSheet.PageSetup.PrintArea = "$B$1:J53"
            ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
        Else
            Exit Sub
        End If

        'effacemment du document
        Range("B15:I40").ClearContents
        Range("Q8").ClearContents
        Range("R8").ClearContents
        Range("J43").ClearContents
        Range("D45").ClearContents
        Range("Q1").ClearContents
        Range("J1").ClearContents
    End If
    Application.ScreenUpdating = True  ' retour a ma facture
    Sheets("facture").Select
End Sub

A+

essai concluant comme cela sa fonctionne parfaitement

merci beaucoup.

cedcyr

Rechercher des sujets similaires à "comprotement message box anormale"