我是VBA的新手,我正在努力解决的问题是在表单中自动填充组合框。 例如,我的组合框列出了以下值: “苹果”,“树”,“果汁” 我在问如何使其在我的列表中进行搜索以及何时编写“ app”为我提供“ apple”结果。
这是我的代码:
Private Sub ComboBox3_Change()
If Me.ComboBox3.Value <> "" Then
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("11")
Set ph = ThisWorkbook.Sheets("22")
Dim i As String
i = Application.Match((Me.ComboBox3.Value), sh.Range("A:A"), 0)
Me.TextBox8.Value = ph.Range("D" & i).Value
Me.TextBox13.Value = ph.Range("P" & i).Value
Me.TextBox41.Value = ph.Range("B" & i).Value
End If
End Sub
Private Sub UserForm_Activate()
Dim i As Integer
Me.ComboBox3.Clear
Me.ComboBox3.AddItem ""
For i = 2 To sh.Range("A" & Application.Rows.Count).End(xlUp).Row
Me.ComboBox3.AddItem sh.Range("A" & i).Value
Next i