我一直在爲此工作2天。基本上我有2個ListBox,我想要一個命令按鈕來比較這些值並顯示不匹配的值(那些出現在第一個列表框但不在第二個列表框中)並將它們列在第三個列表框中。我不確定這是否是最好的方法,但這裏是我的代碼。它的錯誤符合以下消息:比較2個列表框並在第3個列表框中顯示不匹配的值
Wrong number of arguments or invalid property assignment
我的列表框被命名爲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
哪些行源? – Fionnuala 2012-07-26 20:05:28
CompList1和CompList2填充了表格的字段名稱。表名將始終相同,但字段將隨每次使用而改變。行源類型設置爲字段列表。 – JenPhyllisB 2012-07-26 20:07:35