Suivre un inventaire en utilisant un Userform

Résolu/Fermé
bassmart Messages postés 281 Date d'inscription jeudi 19 février 2015 Statut Membre Dernière intervention 19 décembre 2023 - 23 sept. 2015 à 21:16
bassmart Messages postés 281 Date d'inscription jeudi 19 février 2015 Statut Membre Dernière intervention 19 décembre 2023 - 28 sept. 2015 à 20:47
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!
A voir également:

2 réponses

Kuartz Messages postés 850 Date d'inscription vendredi 13 février 2015 Statut Membre Dernière intervention 15 février 2019 61
Modifié par Kuartz le 24/09/2015 à 09:05
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
bassmart Messages postés 281 Date d'inscription jeudi 19 février 2015 Statut Membre Dernière intervention 19 décembre 2023 1
25 sept. 2015 à 16:31
Effectivement Kuartz ça va mieux avec le fichier, désolé!!

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

Merci!
0
michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 3 306
24 sept. 2015 à 09:08
Bonjour

Un contrôle Textbox renvoie du texte...

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

0
michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 3 306
25 sept. 2015 à 16:50
Excuse moi de t'avoir dérangé
bonne continuation
0
bassmart Messages postés 281 Date d'inscription jeudi 19 février 2015 Statut Membre Dernière intervention 19 décembre 2023 1
Modifié par bassmart le 28/09/2015 à 18:25
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
bassmart Messages postés 281 Date d'inscription jeudi 19 février 2015 Statut Membre Dernière intervention 19 décembre 2023 1
28 sept. 2015 à 20:47
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