我以为我有一个有效的子例程,可以用两个数组中的前4个搜索结果来填充组合框下拉列表,但是现在当我第一次单击它时,有时会给出四个不相关的结果。但是当子例程运行时,它会将此奇怪的递增事物作为其下拉列表。 这是正在运行的子例程:
Sub ComboFill()
ComboBox1.Clear
If ComboBox1.Value = "" Then
Exit Sub
Else
Dim Ships As Variant
Dim People As Variant
People = Filter(Module1.FullPeopleArray, ComboBox1.Value, True, vbTextCompare)
Ships = Filter(Module1.ShipsColumnHeads, ComboBox1.Value, True, vbTextCompare)
If UBound(People) > 0 And UBound(People) <= 3 Then
For Each ComboLine In People
ComboBox1.AddItem ComboLine
Next ComboLine
ElseIf UBound(People) > 3 Then
For ComboLine = 0 To 3
ComboBox1.AddItem People(ComboLine)
Next ComboLine
End If
If ComboBox1.ListCount < 3 Then
If UBound(Ships) > 0 And UBound(Ships) <= 3 - ComboBox1.ListCount Then
For Each ComboLine In Ships
ComboBox1.AddItem ComboLine
Next ComboLine
ElseIf UBound(People) > 3 - ComboBox1.ListCount Then
For ComboLine = 0 To 3 - ComboBox1.ListCount
ComboBox1.AddItem People(ComboLine)
Next ComboLine
End If
End If
End If
End Sub
我可能不知道我在处理其中的某些行,所以我可能会完全以错误的方式进行操作。