1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| 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
list
End Sub
Private Sub CommandButton2_Click()
' Annuler
Unload Me
End Sub
Private Sub UserForm_Initialize()
list
End Sub
Sub list()
Dim I As Integer
'Charge les données de produits
Set Ws = Sheets("data")
With Me.ComboBox1
.Clear
For I = 1 To Ws.Range("B2").End(xlToRight).Column
.AddItem Ws.Cells(1, I)
Next I
End With
End Sub |
Partager