我想在VB userform中创建一个通配符搜索类型组合框。 搜索目标位于excel列。
我可以用:
Private Sub Combobox1_Populate(Optional fltr As String)
ComboBox1.List = Filter(Array("a", "ab", "abc", "abcd"), fltr)
End Sub
但使用时失败:
Sub Combobox1_Populate(Optional fltr As String)
ComboBox1.List = Filter(Array(Range("A1:A9")), fltr)**
End Sub
运行时错误' 13'
类型不匹配
为什么Filter(Array(Range
无效?请帮助纠正它。
它也没有问题。合并过滤器
时只有Array(Range
不起作用
Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Call Combobox1_Populate(ComboBox1.Text)
End Sub
Private Sub UserForm_Initialize()
Call Combobox1_Populate
End Sub
答案 0 :(得分:0)
尝试以下代码:
Sub Combobox1_Populate(Optional fltr As String)
ComboBox1.List = Filter(Application.Transpose(Range("A1:A9")), fltr)
End Sub
'==============================================================
Private Sub UserForm_Initialize()
Call Combobox1_Populate("shai") '<-- add the filter string in brackets, I've tested with "shai"
End Sub