Bonsoir
J ai créé un formulaire pour une gestion d'un petit stock et je rencontre 3 difficultés ( pour l'instant )
1) j ai 2 ComboBox mais les listes correspondantes ne sont pas dynamiques
2 ) D autre part, dans les combobox renvoient des données en format texte qui empêchent la fonction RechercheV de fonctionner correctement.
3) je souhaiterais que le bouton "Valider" remettre le formulaire à zéro pour une autre saisie
Merci pour votre aide
Option Explicit
Dim Ws As Worksheet
Private Sub ComboBox1_Change()
' Produits
Dim J As Long
Dim Colonne As Integer
Me.ComboBox2.Clear
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
Colonne = Me.ComboBox1.ListIndex + 1
For J = 2 To Ws.Cells(Rows.Count, Colonne).End(xlUp).Row
Me.ComboBox2.AddItem Ws.Cells(J, Colonne)
Next J
End Sub
Private Sub ComboBox2_Change()
' Références
Me.TextBox1 = ""
If Me.ComboBox2.ListIndex = -1 Then Exit Sub
Me.TextBox1 = Me.ComboBox2
End Sub
Private Sub CommandButton1_Click()
' Valider
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = Me.ComboBox1
If Me.ComboBox2.ListIndex = -1 Then Exit Sub
Range("B" & Rows.Count).End(xlUp).Offset(1, 0) = Me.TextBox1
Range("E" & Rows.Count).End(xlUp).Offset(1, 0) = Me.TextBox2
End Sub
Private Sub CommandButton2_Click()
' Annuler
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim I As Integer
'Charge les données de produits
Set Ws = Sheets("data")
With Me.ComboBox1
For I = 1 To Ws.Range("B2").End(xlToRight).Column
.AddItem Ws.Cells(1, I)
Next I
End With
End Sub
cordialement