Excel中的VBA组合框,用于搜索引擎无效的属性阵列索引(错误381)
附加信息。
VBA代码是搜索引擎,目的是在我使用公式过滤的另一个表上获取客户详细信息列表(名称)。
这是背景数据工作表。 工作表“背景数据” 通过使用值我输入组合框上的过滤。
它在组合盒上工作, 这是结果 但是,当我单击任何客户名称时, 下面的错误弹出。
我在Excel中的VBA代码上有问题,
你们可以帮助我如何解决此错误。
无效的属性阵列索引(错误381)
Option Explicit
Private Comb_Arrow As Boolean
Private Sub search_engine_Change()
Dim i As Long
If Not Comb_Arrow Then
With Me.search_engine
.list = Worksheets("BACKGROUND DATA").Range("B2", Worksheets("BACKGROUND DATA").Cells(Rows.Count, "B").End(xlUp)).Value
.ListRows = Application.WorksheetFunction.Min(4, .ListCount)
.DropDown
If Len(.Text) Then
For i = .ListCount - 1 To 0 Step -1
If InStr(1, .list(i), .Text, vbTextCompare) = 0 Then .RemoveItem i
Next
.DropDown
End If
End With
End If
End Sub
Private Sub search_engine_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Comb_Arrow = (KeyCode = vbKeyUp) Or (KeyCode = vbKeyDown)
If KeyCode = vbKeyReturn Then Me.search_engine.list = Worksheets("BACKGROUND DATA").Range _
("B2", Worksheets("BACKGROUND DATA").Cells(Rows.Count, "B").End(xlUp)).Value
End Sub
Additional Information.
The vba code is the search engine, purpose of taking the list of customers details (name) on the other sheet which i filter with formula.
This is the background data worksheets.
Worksheets "background data"
Was filter by using by value i enter on the combo box.
It works on the combo box,
This is the result
But when i click on any customer name,
the error below pop up.
I have problem on vba code in excel
can you guys help me how to fix this error.
Invalid property-array index (Error 381)
Option Explicit
Private Comb_Arrow As Boolean
Private Sub search_engine_Change()
Dim i As Long
If Not Comb_Arrow Then
With Me.search_engine
.list = Worksheets("BACKGROUND DATA").Range("B2", Worksheets("BACKGROUND DATA").Cells(Rows.Count, "B").End(xlUp)).Value
.ListRows = Application.WorksheetFunction.Min(4, .ListCount)
.DropDown
If Len(.Text) Then
For i = .ListCount - 1 To 0 Step -1
If InStr(1, .list(i), .Text, vbTextCompare) = 0 Then .RemoveItem i
Next
.DropDown
End If
End With
End If
End Sub
Private Sub search_engine_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Comb_Arrow = (KeyCode = vbKeyUp) Or (KeyCode = vbKeyDown)
If KeyCode = vbKeyReturn Then Me.search_engine.list = Worksheets("BACKGROUND DATA").Range _
("B2", Worksheets("BACKGROUND DATA").Cells(Rows.Count, "B").End(xlUp)).Value
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于这一行:
范围对象只采用一个参数,您正在尝试发送2。如果您希望拥有多个单元格范围,例如B2:b5,那么您将无法获得该范围的值,因为它将具有多个值。这条线似乎都有多个问题。
如果您提供有关您要实现的目标的更多数据,那么它将提供进一步的帮助。您想通过第二个论点要实现什么?您要寻找什么价值?
The problem lies in this line:
The range object only takes a single argument, you are trying to send it 2. If you are looking to have a multi cell range, such as B2:B5, then you cannot take a value of that range, as it will have multiple values. All around this line appears to have multiple problems.
If you provide more data as to what you are trying to achieve, it will be of further help. What are you trying to achieve with the second argument? What value are you looking for?