【发布时间】:2015-07-30 00:27:31
【问题描述】:
我正在编写 vba 代码,它将针对工作表中的整个列搜索所有列表框项。 如果在 Excel 工作表列中找不到列表框项目,我想从列表中删除该项目。我尝试了一些代码,它显示一些错误为“无法获取列表属性,无效的属性数组索引”。以下是我目前正在使用的代码。
Private Sub CommandButton1_Click()
Dim itemExistResults As Boolean
Dim myarray()
Dim intItem As Long
myarray = Application.Transpose(Sheet1.Range("a2:a1000"))
For intItem = 0 To ListBox1.ListCount - 1
If IsInArray(ListBox1.List(intItem), myarray) Then
Else
ListBox1.RemoveItem intItem
End If
Next
End Sub
Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
IsInArray = UBound(Filter(arr, stringToBeFound)) > -1
End Function
知道我在这段代码中哪里错了。
【问题讨论】:
标签: vba