|
Private Sub ComboBox1_Change()
Dim rn As Range
Dim r As Long, i As Long
zd = ComboBox1.Text
If zd = "" Then Exit Sub
r = Cells(Rows.Count, 1).End(xlUp).Row
Set rn = Range("a2:a" & r).Find(zd, , , , , , 1)
w = rn.Row
TextBox1.Text = Cells(w, 2)
TextBox2.Text = Cells(w, 3)
End Sub
Private Sub CommandButton1_Click()
rr = Array(ComboBox1.Text, TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text)
For i = 0 To UBound(rr)
If rr(i) = "" Then
MsgBox "请把信息录入完整!": Exit Sub
End If
Next i
With Sheet2
r = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(r, 1).Resize(1, 6) = rr
End With
For i = 1 To 5
Controls("TextBox" & i) = ""
Next i
MsgBox "ok!"
End Sub
Private Sub UserForm_Initialize()
Dim r As Long, i As Long
r = Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "数据源为空!": Exit Sub
ar = Range("a2:a" & r)
ComboBox1.List = ar
End Sub
|
|