Code NOUVEAU CONTACT

slt j'aimerai si mon code est bon pour le bouton NOUVEAU CONTACT :

`Pour le bouton Nouveau contact
Private Sub CommandButton1_Click()
 Dim L As Integer
 If MsgBox("Confirmez-vous l'insertion de ce nouveau contact ?", vbYesNo, "Demande de
confirmation d'ajout") = vbYes Then
 L = Sheets("Clients").Range("a65536").End(xlUp).Row + 1 `Pour placer le nouvel
enregistrement à la première ligne de tableau non vide
 Range("A" & L).Value = ComboBox1
 Range("B" & L).Value = ComboBox2
 Range("C" & L).Value = TextBox1
 Range("D" & L).Value = TextBox2
 Range("E" & L).Value = TextBox3
 Range("F" & L).Value = TextBox4
 Range("G" & L).Value = TextBox5
 Range("H" & L).Value = TextBox6
 Range("I" & L).Value = TextBox7
 Range("J" & L).Value = TextBox8
 Range("K" & L).Value = TextBox9
 Range("L" & L).Value = TextBox10
 Range("M" & L).Value = TextBox11
 Range("N" & L).Value = TextBox12

 Range("G" & L).Value = TextBox5
 Range("H" & L).Value = TextBox6
 Range("I" & L).Value = TextBox7
 End If
End Sub


EDIT: Ajout de la coloration syntaxique.

6 réponses

  1. Bonjour,

    vous ajoutez en fin de tableau, mais deux fois GHI !!!!!!
    1. bonjour ,

      j'ai retiré en fin de tableau " GHI " comme vous l'avez suggérer mais je retrouve toujours le même message d'erreur.

      erreur compilation
      erreur syntaxe

      merci pour votre réponse .
      1. Modérateur
        Bonjour,

        Dans votre code, vérifiez vos apostrophes avant les commentaires.
        ` n'est pas identique à : '

        1. merci pour votre réponse cela dit lorsque je compile on me dit :

          erreur syntax et la parti soulignée est marqué en rouge.
          Private Sub CommandButton3_Click() est marqué en jaune

          le code :

          Private Sub CommandButton3_Click()

          Dim L As Integer
          If MsgBox("Confirmez-vous l'insertion de ce nouveau contact ?", vbYesNo, "Demande de confirmation ") = vbYes Then"
          L = Sheets("Clients").Range("a65536").End(xlUp).Row + 1
          Range("A" & L).Value = ComboBox1
          Range("B" & L).Value = ComboBox2
          Range("C" & L).Value = TextBox1
          Range("D" & L).Value = TextBox2
          Range("E" & L).Value = TextBox3
          Range("F" & L).Value = TextBox4
          Range("G" & L).Value = TextBox5
          Range("H" & L).Value = TextBox6
          Range("I" & L).Value = TextBox7
          Range("J" & L).Value = TextBox8
          Range("K" & L).Value = TextBox9
          Range("L" & L).Value = TextBox10
          Range("M" & L).Value = TextBox11
          Range("N" & L).Value = TextBox12

          End If
          End Sub
          1. Modérateur
            Il ne semble pas y avoir d'erreur dans ce code, à part les guillemets en trop après vbYes Then...

            Peut être y verrions nous plus clair avec le fichier.
        2. Bonjour,

          je vous remercie pour toute vos réponses elle m'ont permi d'avancer .
          la quant je compile on me demande dans la boite de Dialogue si "" Confirmez-vous l'insertion de ce nouveau contact '' OUI/NON . et lorsque je clik sur oui on m'envoi une autre boite de Dialogue pour me dire :

          erreur d'execution '9'
          L'indice n'appartient pas à la selection

          voici le code ;

          Private Sub CommandButton3_Click() 
          
          Dim L As Integer 
          If MsgBox("Confirmez-vous l'insertion de ce nouveau contact ?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then 
          L = Sheets("Clients").Range("a65536").End(xlUp).Row + 1 
          Range("A" & L).Value = ComboBox1 
          Range("B" & L).Value = ComboBox2 
          Range("C" & L).Value = TextBox1 
          Range("D" & L).Value = TextBox2 
          Range("E" & L).Value = TextBox3 
          Range("F" & L).Value = TextBox4 
          Range("G" & L).Value = TextBox5 
          Range("H" & L).Value = TextBox6 
          Range("I" & L).Value = TextBox7 
          Range("J" & L).Value = TextBox8 
          Range("K" & L).Value = TextBox9 
          Range("L" & L).Value = TextBox10 
          Range("M" & L).Value = TextBox11 
          Range("N" & L).Value = TextBox12 
          
          End If 
          End Sub 


          merci de me répondre
          1. Modérateur
            Essaye :

            Private Sub CommandButton3_Click() 
            Dim L As Integer 
            If MsgBox("Confirmez-vous l'insertion de ce nouveau contact ?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then 
                With Sheets("Clients")
                    L = .Range("A65536").End(xlUp).Row + 1 
                    .Range("A" & L).Value = ComboBox1 
                    .Range("B" & L).Value = ComboBox2 
                    .Range("C" & L).Value = TextBox1 
                    .Range("D" & L).Value = TextBox2 
                    .Range("E" & L).Value = TextBox3 
                    .Range("F" & L).Value = TextBox4 
                    .Range("G" & L).Value = TextBox5 
                    .Range("H" & L).Value = TextBox6 
                    .Range("I" & L).Value = TextBox7 
                    .Range("J" & L).Value = TextBox8 
                    .Range("K" & L).Value = TextBox9 
                    .Range("L" & L).Value = TextBox10 
                    .Range("M" & L).Value = TextBox11 
                    .Range("N" & L).Value = TextBox12 
                End With
            End If 
            End Sub


            Nota : si Excel version 2007 et supérieure, la syntaxe
            Range("A65536").End(xlUp).Row
            est à éviter. Voir ICI.