Suivre un inventaire en utilisant un Userform

Résolu
bassmart Messages postés 281 Date d'inscription   Statut Membre Dernière intervention   -  
bassmart Messages postés 281 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour à tous!

J'ai créer un userform pour me permettre de tenir un inventaire. Quand je reçoit une livraison de matériel, j'utilise se formulaire pour ajouter les quantités reçue selon leurs longueurs.

Mais voilà, je n'y pas arrivé!!

J'ai essayé les fonctions "IF" et "for each" mais sans succès!

Voici une partie du code que j'ai créer sur le userform:
Private Sub CommandButton1_Click()

Sheets("Inventaire").Unprotect
    
    Range("B4") = Range("B4") + TextBox2.Value
   
    Range("B5") = Range("B5") + TextBox3.Value

    Range("B6") = Range("B6") + TextBox4.Value

    Range("B7") = Range("B7") + TextBox5.Value

    Range("B8") = Range("B8") + TextBox6.Value

    Range("B9") = Range("B9") + TextBox7.Value

    Range("B10") = Range("B10") + TextBox8.Value

    Range("B11") = Range("B11") + TextBox9.Value

    Range("b13") = Range("b13") + TextBox10.Value

    Range("b15") = Range("b15") + TextBox11.Value

    Range("b17") = Range("b17") + TextBox12.Value


If ComboBox1 = "" Then
    MsgBox "Choisissez un nom dans la liste!"
Else
    Unload Me
End If
    
Range("B22") = ComboBox1.Value
Sheets("Inventaire").Protect

End Sub


Merci pour votre aide!

2 réponses

  1. Kuartz Messages postés 852 Date d'inscription   Statut Membre Dernière intervention   65
     
    Bonjour,

    Merci de joindre un fichier anonymé sur : https://www.cjoint.com/

    Franchement avec un userform, il faut vraiment mieux le faire comme ca, sinon c'est très difficile de voir à quoi ressemble le truc.

    Cordialement.
    0
    1. bassmart Messages postés 281 Date d'inscription   Statut Membre Dernière intervention   1
       
      Effectivement Kuartz ça va mieux avec le fichier, désolé!!

      Voici le lien : http://www.cjoint.com/c/EIzoDSYlbPo

      Merci!
      0
  2. michel_m Messages postés 18903 Date d'inscription   Statut Contributeur Dernière intervention   3 320
     
    Bonjour

    Un contrôle Textbox renvoie du texte...

    Range("B2") = Range("B2") + TextBox1 * 1

    0
    1. michel_m Messages postés 18903 Date d'inscription   Statut Contributeur Dernière intervention   3 320
       
      Excuse moi de t'avoir dérangé
      bonne continuation
      0
    2. bassmart Messages postés 281 Date d'inscription   Statut Membre Dernière intervention   1
       
      Je pense avoir trouvé une solution, ce n'est probablement la plus efficace, mais ça fonctionne. Voici mon code:

      Private Sub CommandButton1_Click()
      
      Sheets("Inventaire").Unprotect
      
      If TextBox2 = IsNumeric(TextBox2) Then
          Range("B4") = Range("B4") + TextBox2.Value
      End If
      
      If TextBox3 = IsNumeric(TextBox3) Then
          Range("B5") = Range("B5") + TextBox3.Value
      End If
      
      If TextBox4 = IsNumeric(TextBox4) Then
          Range("B6") = Range("B6") + TextBox4.Value
      End If
      
      If TextBox5 = IsNumeric(TextBox5) Then
          Range("B7") = Range("B7") + TextBox5.Value
      End If
      
      If TextBox6 = IsNumeric(TextBox6) Then
          Range("B8") = Range("B8") + TextBox6.Value
      End If
      
      If TextBox7 = IsNumeric(TextBox7) Then
          Range("B9") = Range("B9") + TextBox7.Value
      End If
      
      If TextBox8 = IsNumeric(TextBox8) Then
          Range("B10") = Range("B10") + TextBox8.Value
      End If
      
      If TextBox9 = IsNumeric(TextBox9) Then
          Range("B11") = Range("B11") + TextBox9.Value
      End If
      
      If TextBox10 = IsNumeric(TextBox10) Then
          Range("b13") = Range("b13") + TextBox10.Value
      End If
      
      If TextBox11 = IsNumeric(TextBox11) Then
          Range("b15") = Range("b15") + TextBox11.Value
      End If
      
      If TextBox12 = IsNumeric(TextBox12) Then
          Range("b17") = Range("b17") + TextBox12.Value
      End If
      
      
      If ComboBox1 = "" Then
          MsgBox "Choisissez un nom dans la liste!"
      Else
          Unload Me
      End If
          
      Range("B22") = ComboBox1.Value
      Sheets("Inventaire").Protect
      
      End Sub


      Qu'en pensez-vous?

      Merci!
      0
    3. bassmart Messages postés 281 Date d'inscription   Statut Membre Dernière intervention   1
       
      Est-ce qu'il y a un moyen de simplifier tout ça et d'ajouter une validation pour que la valeur soit numérique sinon il envoi un message d'erreur du genre
      If TextBox3 = IsNumeric(TextBox3) Then
          Range("C4") = Range("C4") + TextBox3.Value
      ElseIf Not IsNumeric(TextBox3) Then
          MsgBox "Valeur non numériques!", vbCritical
      End If
      Ce code fonctionne, mais je doit le copier pour chacun des textbox, c'est un peu lourd!

      Merci pour votre aide!
      0