Effacer certains champs d'un userform après sauvagrde

misschoupi -  
 misschoupi -
Bonjour, Je débute en VBA et non sans douleur!!!

J'ai ce morceau de code :

'Si le formulaire est complet, on insère les valeurs sur la feuille
Dim no_ligne As Integer
Dim i
i = MsgBox("Souhaitez-vous faire une demande supplémentaire pour la même CELLULE ? ", vbYesNo, "Demande supplémentaire ")
'Ok renvois i=1, Cancel renvois i = 2, fermeture à la croix renvois i = 2
If i = vbYes Then
CommandButton_Ajouter.Caption = "Sauvegarde obligatoire"
CommandButton_Ajouter.BackColor = RGB(255, 0, 0)
CommandButton1_ENVOI.Visible = False

Sheets("Fiche").Activate
'no_ligne = N° de ligne de la dernière cellule non vide de la colonne +1
no_ligne = Range("A65536").End(xlUp).Row + 1

'Insertion des valeurs sur la feuille

Cells(no_ligne, 1) = TextBox_compteur.Value
Cells(no_ligne, 2) = ComboBox_AGENCE.Value
Cells(no_ligne, 3) = ComboBox_EMETTEUR.Value
Cells(no_ligne, 4) = DTPicker1.Value
Cells(no_ligne, 5) = ComboBox_MOTIF.Value
Cells(no_ligne, 6) = TextBox1_DESIGNATION.Value
Cells(no_ligne, 7) = ComboBox1_FRNS.Value
Cells(no_ligne, 8) = TextBox_REF_FRNS.Value
Cells(no_ligne, 9) = TextBox_PV.Value
Cells(no_ligne, 10) = ComboBox_UV.Value
Cells(no_ligne, 11) = TextBoxPHA.Value
Cells(no_ligne, 12) = TextBoxPOIDS.Value
Cells(no_ligne, 13) = TextBoxTYPE_DIM1.Value & " = " & TextBox_VALEUR_DIM1.Value & " " & ComboBox_UNITE_DIM1.Value & " / " & TextBoxTYPE_DIM2.Value & " = " & TextBox_VALEUR_DIM2.Value & " " & ComboBox_UNITE_DIM2.Value & " / " & TextBoxTYPE_DIM3.Value & " = " & TextBox_VALEUR_DIM3.Value & " " & ComboBox_UNITE_DIM3.Value
Cells(no_ligne, 14) = ComboBox_CELLULE.Value
Sheets("Création").Activate

Else
CommandButton_Ajouter.Caption = "Sauvegarde terminée"
CommandButton_Ajouter.BackColor = RGB(0, 255, 0)
CommandButton_Ajouter.Visible = False
CommandButton1_ENVOI.Visible = True
Sheets("Fiche").Activate
'no_ligne = N° de ligne de la dernière cellule non vide de la colonne +1
no_ligne = Range("A65536").End(xlUp).Row + 1

'Insertion des valeurs sur la feuille
Cells(no_ligne, 1) = TextBox_compteur.Value
Cells(no_ligne, 2) = ComboBox_AGENCE.Value
Cells(no_ligne, 3) = ComboBox_EMETTEUR.Value
Cells(no_ligne, 4) = DTPicker1.Value
Cells(no_ligne, 5) = ComboBox_MOTIF.Value
Cells(no_ligne, 6) = TextBox1_DESIGNATION.Value
Cells(no_ligne, 7) = ComboBox1_FRNS.Value
Cells(no_ligne, 8) = TextBox_REF_FRNS.Value
Cells(no_ligne, 9) = TextBox_PV.Value
Cells(no_ligne, 10) = ComboBox_UV.Value
Cells(no_ligne, 11) = TextBoxPHA.Value
Cells(no_ligne, 12) = TextBoxPOIDS.Value
Cells(no_ligne, 13) = TextBoxTYPE_DIM1.Value & " = " & TextBox_VALEUR_DIM1.Value & " " & ComboBox_UNITE_DIM1.Value & " / " & TextBoxTYPE_DIM2.Value & " = " & TextBox_VALEUR_DIM2.Value & " " & ComboBox_UNITE_DIM2.Value & " / " & TextBoxTYPE_DIM3.Value & " = " & TextBox_VALEUR_DIM3.Value & " " & ComboBox_UNITE_DIM3.Value
Cells(no_ligne, 14) = ComboBox_CELLULE.Value
Sheets("Création").Activate
End If

Je souhaiterai effacer certains champs du userform après les avoir renseigné dans l'onglet "fiche" lorsque que i=vbyes. Seuls les champs AGENCE, EMETTEUR et CELLULE ne doivent pas être réinitialisés. Cela fait des heures, des jours que je tente des choses et à chaque fois, cela m'efface dans l'onglet fiche, une ligne. Pouvez-vous m'aider, s'il vous plait. Merci d'avance

1 réponse

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

    raz textebox------>TextBox_xxxxx=""
    raz combobox---->ComboBox_xxxxx=""
    raz dtpiker------->DTPiker="" a voir

    quel est le rapport entre les raz de champs et votre ligne qui disparait ?????

    A+
    0
    1. misschoupi
       
      Bonjour et merci pour votre réactivité.

      J'ai essayé cela mais cela m'écrase la saisie précédente. J'avais écris par exemple TextBox_DESIGNATION.value="" à l'intérieur du if i=vbyes
      0
    2. f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   1 717
       
      Re,

      Avez-vous mis la raz des champs apres l'ecriture des cellules ??????
      0
    3. f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   1 717
       
      Re,

      m'écrase la saisie précédente ??????

      Avez-vous mis la raz des champs apres l'ecriture des cellules de votre feuille ???
      0
    4. misschoupi
       
      Comment faudrait-il que je l'écrive. Pouvez-vous me donner un exemple?
      0
    5. f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   1 717
       
      Re,

      Ce que je ne comprends pas, que la reponse soit oui ou non, vous ecrivez une ligne supplementaire!!!!!


      Sub test()
          Dim no_ligne As Integer
          Dim i
          i = MsgBox("Souhaitez-vous faire une demande supplémentaire pour la même CELLULE ? ", vbYesNo, "Demande supplémentaire ")
          'Ok renvois i=1, Cancel renvois i = 2, fermeture à la croix renvois i = 2
          Sheets("Fiche").Activate
          'no_ligne = N° de ligne de la dernière cellule non vide de la colonne +1
          no_ligne = Range("A65536").End(xlUp).Row + 1
          If i = vbYes Then
              CommandButton_Ajouter.Caption = "Sauvegarde obligatoire"
              CommandButton_Ajouter.BackColor = RGB(255, 0, 0)
              CommandButton1_ENVOI.Visible = False
      
          Else
              CommandButton_Ajouter.Caption = "Sauvegarde terminée"
              CommandButton_Ajouter.BackColor = RGB(0, 255, 0)
              CommandButton_Ajouter.Visible = False
              CommandButton1_ENVOI.Visible = True
          End If
          
          'Insertion des valeurs sur la feuille
          Cells(no_ligne, 1) = TextBox_compteur.Value
          Cells(no_ligne, 2) = ComboBox_AGENCE.Value
          Cells(no_ligne, 3) = ComboBox_EMETTEUR.Value
          Cells(no_ligne, 4) = DTPicker1.Value
          Cells(no_ligne, 5) = ComboBox_MOTIF.Value
          Cells(no_ligne, 6) = TextBox1_DESIGNATION.Value
          Cells(no_ligne, 7) = ComboBox1_FRNS.Value
          Cells(no_ligne, 8) = TextBox_REF_FRNS.Value
          Cells(no_ligne, 9) = TextBox_PV.Value
          Cells(no_ligne, 10) = ComboBox_UV.Value
          Cells(no_ligne, 11) = TextBoxPHA.Value
          Cells(no_ligne, 12) = TextBoxPOIDS.Value
          Cells(no_ligne, 13) = TextBoxTYPE_DIM1.Value & " = " & _
                                             TextBox_VALEUR_DIM1.Value & " " & _
                                             ComboBox_UNITE_DIM1.Value & " / " & _
                                             TextBoxTYPE_DIM2.Value & " = " & _
                                             TextBox_VALEUR_DIM2.Value & " " & _
                                             ComboBox_UNITE_DIM2.Value & " / " & _
                                             TextBoxTYPE_DIM3.Value & " = " & _
                                             TextBox_VALEUR_DIM3.Value & " " & _
                                             ComboBox_UNITE_DIM3.Value
          Cells(no_ligne, 14) = ComboBox_CELLULE.Value
          
          If i = vbYes Then
              TextBox_compteur = ""
              'pas de raz ComboBox_AGENCE.Value
              'pas de raz ComboBox_EMETTEUR.Value
              DTPicker1 = ""
              ComboBox_MOTIF = ""
              TextBox1_DESIGNATION = ""
              ComboBox1_FRNS = ""
              TextBox_REF_FRNS = ""
              TextBox_PV = ""
              ComboBox_UV = ""
              TextBoxPHA = ""
              TextBoxPOIDS = ""
              TextBoxTYPE_DIM1 = ""
              TextBox_VALEUR_DIM1 = ""
              ComboBox_UNITE_DIM1 = ""
              TextBoxTYPE_DIM2 = ""
              TextBox_VALEUR_DIM2 = ""
              ComboBox_UNITE_DIM2 = ""
              TextBoxTYPE_DIM3 = ""
              TextBox_VALEUR_DIM3 = ""
              ComboBox_UNITE_DIM3 = ""
              'pas de raz ComboBox_CELLULE.Value
          End If
          Sheets("Création").Activate
      
      End Sub


      A+
      0