我已经为此工作了 2 天。基本上我有 2 个列表框,我想要一个命令按钮来比较值并显示不匹配的值(那些出现在第一个列表框中但不在第二个列表框中的值)并将它们列出在第三个列表框中。我不确定这是否是最好的方法,但这是我的代码。它与以下消息一致:
参数数量错误或属性分配无效
我的列表框被命名为 CompList1、CompList2 和 CompList3。
Dim BoolAdd As Boolean, I As Long, j As Long
'Set initial Flag
BoolAdd = True
'If CompList2 is empty then abort operation
If CompList2.ListCount = 0 Then
MsgBox "Nothing to compare"
Exit Sub
'If CompList1 is empty then copy entire CompList2 to CompList3
ElseIf CompList1.ListCount = 0 Then
For I = 0 To CompList2.ListCount
CompList3.AddItem CompList2.Value
Next I
Else
For I = CompList2.ListCount - 1 To 0 Step -1
For j = 0 To CompList1.ListCount
If CompList2.ListCount(I) = CompList1.ListCount(j) Then
'If match found then abort
BoolAdd = False
Exit For
End If
DoEvents
Next j
'If not found then add to CompList3
If BoolAdd = True Then CompList3.AddItem CompList2.Value
DoEvents
Next I
End If