Excel中的VBA组合框,用于搜索引擎无效的属性阵列索引(错误381)

发布于 2025-02-11 04:40:03 字数 1616 浏览 1 评论 0原文

附加信息。

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)

THIS IS THE ERROR PICTURE

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不气馁 2025-02-18 04:40:03
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
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
甜扑 2025-02-18 04:40:03

问题在于这一行:

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

范围对象只采用一个参数,您正在尝试发送2。如果您希望拥有多个单元格范围,例如B2:b5,那么您将无法获得该范围的值,因为它将具有多个值。这条线似乎都有多个问题。

如果您提供有关您要实现的目标的更多数据,那么它将提供进一步的帮助。您想通过第二个论点要实现什么?您要寻找什么价值?

The problem lies in this line:

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

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文