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 59
| Private Sub ComboBox1_Change()
Dim F3 As Worksheet
Dim plage As Range
Dim C As Range
Set F3 = Sheets("StorageData")
Set plage = F3.Range("A2:A" & F3.Range("A" & Rows.Count).End(xlUp).Row)
Set C = plage.Find(ComboBox1.Value, LookIn:=xlValues, lookat:=xlWhole)
If Not C Is Nothing Then
TextBox1.Visible = True
TextBox1.Value = F3.Cells(C.Row, 2)
Else
TextBox1.Visible = False
TextBox1.Value = ""
End If
End Sub
Private Sub CommandButton1_Click()
Dim F3 As Worksheet
Set F3 = Sheets("StorageData")
Dim plage As Range
Dim C As Range
Dim derlig As Long
derlig = F3.Cells(Rows.Count, 1).End(xlUp).Row + 1
Set plage = F3.Range("A2:A" & F3.Range("A" & Rows.Count).End(xlUp).Row)
Set C = plage.Find(ComboBox1.Value, LookIn:=xlValues, lookat:=xlWhole)
If Not C Is Nothing Then
F3.Cells(C.Row, 2) = ComboBox2.Value
Else
F3.Cells(derlig, 1) = ComboBox1.Value
F3.Cells(derlig, 2) = ComboBox2.Value
End If
ComboBox1.Value = ""
ComboBox2.Value = ""
TextBox1.Value = ""
Unload Me
UserForm1.Show
End Sub
Private Sub UserForm_Initialize()
Dim F1 As Worksheet
Dim F2 As Worksheet
Dim i As Long
Dim j As Long
Set F1 = Sheets("Materials")
Set F2 = Sheets("Sbins")
For i = 2 To F1.Range("A65536").End(xlUp).Row
ComboBox1 = F1.Range("A" & i)
If ComboBox1.ListIndex = -1 Then ComboBox1.AddItem F1.Range("A" & i)
Next i
For j = 2 To F2.Range("A65536").End(xlUp).Row
ComboBox2 = F2.Range("A" & j)
If ComboBox2.ListIndex = -1 Then ComboBox2.AddItem F2.Range("A" & j)
Next j
ComboBox1.Value = ""
ComboBox2.Value = ""
TextBox1.Visible = False
End Sub |
Partager