vba 在 2 个不同的 excel 文件中的 2 个不同列中查找匹配值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11780967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
find matching values in 2 different columns in 2 different excel file
提问by jevon_alex
Hi new to vba in excel 2007
嗨,excel 2007 中的 vba 新手
Here is the scenario I want to write a macro where a value in column A from abc.xls is in column c from .xyz.xls. If someone can help me out with this logic and can easily finish the rest. Thank you for your time.
这是我想编写一个宏的场景,其中 abc.xls 中的 A 列中的值位于 .xyz.xls 中的 c 列中。如果有人可以帮助我解决这个逻辑并且可以轻松完成其余部分。感谢您的时间。
回答by Jon Kelly
Welcome to SO. Going on what Tim said in his comment vlookup()
is an easy way to find a value in another sheet. In your case the function would look something like this:
欢迎来到 SO。继续 Tim 在评论中所说的内容vlookup()
是在另一张工作表中查找值的简单方法。在你的情况下,函数看起来像这样:
vlookup([abc.xls]Sheet1!A1, [xyz.xls]Sheet1!C:C, 1, False)
The first part is the value to look up, the second part is the table to look for the value in (in our case only the one row), the third part is which column of the table to return the value from, and the third part tells it to find an exact match. So this function will look for the value in A1 of abc.xls in column C of xyz.xls and return that value if it finds it.
第一部分是要查找的值,第二部分是要查找值的表(在我们的例子中只有一行),第三部分是从表的哪一列返回值,第三部分部分告诉它找到一个完全匹配的。因此,此函数将在 xyz.xls 的 C 列中查找 abc.xls 的 A1 中的值,如果找到则返回该值。
If you instead want the row where the value was found use the match function.
如果您想要找到值的行,请使用 match 函数。
match([abc.xls]Sheet1!A1, [xyz.xls]Sheet1!C:C, 0)
This will do the same thing as vlookup but return the row where it found the match instead.
这将执行与 vlookup 相同的操作,但会返回找到匹配项的行。
Note that you don't have to type these formulas in directly. If you navigate to a new workbook and select the cell it should generate the reference just as if you had selected one from the current sheet.
请注意,您不必直接输入这些公式。如果您导航到一个新工作簿并选择单元格,它应该生成引用,就像您从当前工作表中选择一个一样。