从下拉列表中的列表或表中添加数据

时间:2019-01-18 08:55:17

标签: excel vba

enter image description here嗨,

我在VBA中有一个使用下拉列表的用户窗体,我想从Excel sheet2中已经创建的列表中的下拉按钮中获取数据。但是不知道该怎么做。请帮我,在此先多谢。

Private Sub ComboBox1_Change()
Dim hq As String, asheet As Worksheet, acell As Range
Dim lrow As Double, test As String
Set asheet = ThisWorkbook.Sheets(2)

hq = ComboBox1.Value
Set acell = asheet.Range("$AQ$1:$FR$95").Find(what:=hq, LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False, searchformat:=False)
asheet.Activate
acell.Activate
Selection.End(xlDown).Select
lrow = Selection.Row + 1

ThisWorkbook.Sheets(3).Activate
End Sub

Private Sub CommandButton1_Click()
If CommandButton1 = True Then
Cells(lrow, acell.Column).Value = TextBox1 & "-" & TextBox2
End If
End Sub

Private Sub TextBox1_Change()
Dim txt1 As String
txt1 = TextBox1.Value
Debug.Print txt1

End Sub

Private Sub TextBox2_Change()
Dim txt2 As String
txt2 = TextBox2.Value
Debug.Print txt2
End Sub

Private Sub UserForm_Click()

End Sub

1 个答案:

答案 0 :(得分:0)

以下查询将为您服务

ComboboxName.List = Sheets("Sheet2").Range("F2:F<SpecifiytheNumber>").Value