gpt4 book ai didi

arrays - VBA 第一个数组项始终为空

转载 作者:行者123 更新时间:2023-12-01 09:31:33 25 4
gpt4 key购买 nike

下面的代码是我从网上找到的几个例子拼凑而成的,我不是VBA专家。

但是 clist 数组中的第一项(以及下拉列表中的第一项)始终为空,我假设它与 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

最佳答案

尝试一下,

    ReDim clist(0)
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
clist(UBound(clist)) = product.Value
ReDim Preserve clist(UBound(clist) + 1)
Exit For
End If
Next kword
Next product
ReDim Preserve clist(UBound(clist) - 1)

关于arrays - VBA 第一个数组项始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46006932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com