Excel中搜索引擎的VBA组合框无效的属性数组索引(错误381)

mv1qrgav  于 2022-12-20  发布在  其他
关注(0)|答案(2)|浏览(272)

其他信息。
该vba代码是搜索引擎,目的是采取客户详细信息(名称)的其他工作表,其中我与公式过滤器列表。
这是后台数据工作表。Worksheets "background data"是通过使用组合框中输入的值进行过滤的。
它适用于组合框,This is the result但当我点击任何客户名称,下面的错误弹出.
我在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
bgtovc5b

bgtovc5b1#

Private Sub search_engine_Change()
Dim i, LRow As Long
LRow = Worksheets("BACKGROUND DATA").Cells(Rows.Count, 2).End(xlUp).Row
If LRow > 1 Then
    If Not Comb_Arrow Then
    With Me.search_engine
       .List = Worksheets("BACKGROUND DATA").Range("B1", Worksheets("BACKGROUND DATA").Cells(Rows.Count, "B").End(xlUp)).Value
       .RemoveItem 0
       .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 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 _
    ("B1", Worksheets("BACKGROUND DATA").Cells(Rows.Count, "B").End(xlUp)).Value
End Sub
luaexgnf

luaexgnf2#

问题出在这一行:

.list = Worksheets("BACKGROUND DATA").Range("B2", Worksheets("BACKGROUND DATA").Cells(Rows.Count, "B").End(xlUp)).Value

range对象只接受一个参数,您试图发送它2。如果您希望有一个多单元格范围,如B2:B5,那么您不能接受该范围的值,因为它将有多个值。这一行周围似乎有多个问题。
如果你能提供更多的数据来说明你想要达到的目标,那将会有更大的帮助。你想用第二个论点达到什么目标?你想要什么样的价值?

相关问题