gpt4 book ai didi

excel - 如何在Excel VBA中修复 "Run-time error ' 380'?

转载 作者:行者123 更新时间:2023-12-02 17:18:36 25 4
gpt4 key购买 nike

我正在 Excel VBA 中向列表框添加超过 10 列。我不断收到运行时错误“380”-无效的属性值。它可以正常工作,直到列表框中的第 9 列。我在其他地方找不到任何合适的解决方案。有谁知道这个问题的解决方法吗?

Private Sub txtSearch_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal 
Shift As Integer)
Dim rng As Range
Set rng = Range("Lookup")
Dim rw
Dim strText As String
strText = LCase(txtSearch.Text)
With ListBox1
.RowSource = ""
.ColumnCount = 12

For Each rw In rng.Rows
If InStr(LCase(Cells(rw.Row, 4)), strText) Then
.AddItem Cells(rw.Row, 1).Value
.List(ListBox1.ListCount - 1, 1) = Cells(rw.Row, 2).Value
.List(ListBox1.ListCount - 1, 2) = Cells(rw.Row, 3).Value
.List(ListBox1.ListCount - 1, 3) = Cells(rw.Row, 4).Value
.List(ListBox1.ListCount - 1, 4) = Cells(rw.Row, 5).Value
.List(ListBox1.ListCount - 1, 5) = Cells(rw.Row, 6).Value
.List(ListBox1.ListCount - 1, 6) = Cells(rw.Row, 7).Value
.List(ListBox1.ListCount - 1, 7) = Cells(rw.Row, 8).Value
.List(ListBox1.ListCount - 1, 8) = Cells(rw.Row, 9).Value
.List(ListBox1.ListCount - 1, 9) = Cells(rw.Row, 10).Value
.List(ListBox1.ListCount - 1, 10) = Cells(rw.Row, 11).Value
.List(ListBox1.ListCount - 1, 11) = Cells(rw.Row, 12).Value
.List(ListBox1.ListCount - 1, 12) = Cells(rw.Row, 13).Value
End If
Next

End With
End Sub

最佳答案

我不知道这是否能解决所有问题,但它肯定会清理一些。另外,我不确定您从哪个工作表中提取 Cells(rw.Row, 2).value 。但它们可能与它中途停止的原因有关。另外,要清理一下它,请尝试附加 For 语句

Private Sub txtSearch_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

Dim rng As Range: Set rng = Range("Lookup")
Dim rw
Dim strText As String: strText = LCase(txtSearch.Text)

With ListBox1
.RowSource = ""
.ColumnCount = 21

For Each rw In rng.Rows
If InStr(LCase(Cells(rw.Row, 4)), strText) Then
.AddItem Cells(rw.Row, 1).Value
For x = 1 To 12 '''Change Worksheet to your Worksheet name
.List(ListBox1.ListCount - 1, x) = Worksheets("Sample").Cells(rw.Row, x + 1).Value2
Next x
End If
Next

End With

End Sub

如果这没有帮助,请尝试@Cyril 对数组所说的内容。

关于excel - 如何在Excel VBA中修复 "Run-time error ' 380'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56672570/

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