3
下面的代码是我在网上找到的几个示例中修补过的,我不是VBA专家。VBA第一个数组项目始终是空的
但数组中的第一项(以及下拉菜单中的第一项)始终为空,我假设它与redim
s有关,但我无法弄清楚。
可能是什么问题?
Private Sub ComboBox1_Change()
ReDim clist(0)
'If any value is input
If ComboBox1.Value <> "" Then
Dim kword As Variant
Dim product As Variant
'For each product description in our sheet table
For Each product In [Produtos[Descrição]].Rows
'Keyword search
For Each kword In Split(ComboBox1.Value, " ")
If InStr(Replace(product.Value, "", " "), kword) And kword <> "" Then
'Issue most likely here
ReDim Preserve clist(UBound(clist) + 1) As Variant
clist(UBound(clist)) = product.Value
Exit For
End If
Next kword
Next product
ComboBox1.list = clist
'If found something
If UBound(clist) > 0 Then
ComboBox1.DropDown
End If
'If no Input just show all products, here it doesn't show a blank item
Else
ComboBox1.list = [Produtos[Descrição]].Value2
End If
End Sub
这给出了一个错误,如果CLIST永远不会在尺寸增大 – Mojimi