excel - Excel VBA在多列上比较2列表框
问题描述
我正在尝试制作一个简单的 VBA 用户窗体来检查 2 个 ListBox 但有 2 个条件
- 检查产品编号
- 如果产品编号正常,则检查产品的数量是否正常
这张图片显示了我找到的代码(我在这里搜索并且几乎没有改变它)只是删除重复项。当然,我知道代码只是检查每个 ListBox 的 1 列。
但是经过长时间的搜索和尝试,我找不到任何方法来检查 listbox1 column2 和 listbox2 column1 THEN 如果它的相等检查 listbox1 column 4 等于 listbox2 colum 2
这是一个简单的库存应用程序,我正在尝试为自己制作。listbox2 将由一些条形码扫描仪填充。
Dim obj As Object
Set obj = CreateObject("Scripting.Dictionary")
'1st ListBox
For i = 1 To ListBox1.ListCount - 1
If Not obj.Exists(CStr(ListBox1.List(i, 1))) Then
obj.Add CStr(ListBox1.List(i, 1)), vbNullString
End If
Next
'2nd ListBox
For i = 1 To ListBox2.ListCount - 1
If Not obj.Exists(CStr(ListBox2.List(i, 0))) Then
'add unique of list 2
obj.Add ListBox2.List(i, 0), vbNullString
Else
'delet duplicte of list 1
obj.Remove ListBox2.List(i, 0)
End If
Next
'add unique list to 3rd ListBox
Dim Key As Variant
ListBox3.List = obj.Keys()
lblerr.Caption = ListBox2.ListCount / 2
解决方案
推荐阅读
- python - 我正在使用 python 脚本为 tableau 服务器创建自动订阅,但在运行脚本错误时遇到问题
- c# - 为什么我收到异常 System.Reflection.TargetInvocationException: 'Exception has been throwed by the target of an invocation.'?
- google-sheets - 如何根据 Google 表格上不同工作表的条件提取唯一行
- angular - NGXS 状态返回对象而不是实际数据
- node.js - 指定跨域资源策略以防止资源被阻止
- javascript - array.includes doesn't work when checking if an iterator exists in array
- python - 在 Python 中按值对矩阵进行排序
- android-studio - 如何删除或最小化android studio资产文件夹中的Audience_Network.dex文件?
- java - Do a HTTP POST instead of a GET
- r - 使用 purrr 和 select 创建二分变量