VBA列值比较
我有两张 Excel 表格。第一张工作表具有以下数据:
Column C
--------
101-AA-103
101-AA-104
101-AA-105
101-BB-101
第二张工作表具有以下数据:
Column A
--------
101-AA-100
101-AA-101
101-AA-102
101-AA-103
我想将第一张工作表中的 C 列与第二张工作表中的 A 列进行比较。例如,需要对照第二张纸上 A 列中的所有行检查第一张纸上 C 列的值 101-AA-103。如果找到该值,则应显示“可用”;否则,“不可用”。我如何编写 VBA 函数来执行此操作?
I have two excel sheets. The first sheet has this data:
Column C
--------
101-AA-103
101-AA-104
101-AA-105
101-BB-101
The second sheet has this data:
Column A
--------
101-AA-100
101-AA-101
101-AA-102
101-AA-103
I want to compare column C from the first sheet with column A from the second sheet. For example, value 101-AA-103 from column C on the first sheet needs to be checked against all the rows in column A on the second sheet. If the value is found, it should say "Available"; otherwise, "Not Available". How can I write a VBA function to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
请注意,您应该计算 maxrows 而不是使用 const 整数。
Try this:
Note that you should calculate maxrows and not use a const integer.
您可以使用 Vlookup 轻松完成此操作:
但是既然您要求使用 VBA,这里有一个函数可以完成此操作,利用字典对象和变体数组来提高效率和速度。
您可以创建一个新的可用性数组并将其转置到 D 列,但我不想让它变得过于复杂。
You could do this really easily using Vlookup:
But since you asked for VBA, here's a function that will do it, utilizing a dictionary object and variant arrays for efficiency and speed.
Technically you could create a new array of availability and transpose it on column D, but I didn't want to make it overly complicated.