vba 根据第一列中的数据比较,将数据从工作表复制到另一工作表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15533238/
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
Copy data from a sheet to another one based on comparison of data in first colomn
提问by user2192335
I have an Excel file with two sheet (Sheet1 and Sheet2). In Sheet1 I have data as shown below: http://i47.tinypic.com/2qulksn.jpgIn Sheet2 I have data as shown below (Not the same number of rows, order of names has changed, and other columns are empty): http://i48.tinypic.com/15gxkev.jpg
我有一个带有两张工作表(Sheet1 和 Sheet2)的 Excel 文件。在 Sheet1 中我有如下所示的数据: http://i47.tinypic.com/2qulksn.jpg在 Sheet2 中我有如下所示的数据(行数不同,名称顺序已更改,其他列为空) : http://i48.tinypic.com/15gxkev.jpg
What I would like to do, is compare Sheet2 with Sheet1, looking at the first column, and when the name matches, then copy entire row from Sheet1 to Sheet2. Do nothing when there is no match ie leave New Person as is.
我想做的是将 Sheet2 与 Sheet1 进行比较,查看第一列,当名称匹配时,然后将整行从 Sheet1 复制到 Sheet2。当没有匹配时什么都不做,即让 New Person 保持原样。
I am sorry I don't know VB to start writing a script you could correct. Thanks in advance for all your replies.
对不起,我不知道 VB 开始编写您可以纠正的脚本。预先感谢您的所有回复。
Regards
问候
采纳答案by Jacob Bolda
Kindly use Vlookup function of excel.
请使用excel的Vlookup功能。
回答by Jacob Bolda
No VB script necessary. Try =vlookup($A2,Sheet1!$A$1:$E$11,column())
in Sheet2!B2.
不需要 VB 脚本。=vlookup($A2,Sheet1!$A$1:$E$11,column())
在 Sheet2!B2 中尝试。
Breakdown: vlookup( lookup value with $ on column only so the row updates as you drag down
, array on sheet1 that you are looking up on - this will change depending on your data table
, column() will output the column number thereby giving the column in your array you want to output - will only work if the data headings and cell locations are the exact same
)
细分: vlookup( lookup value with $ on column only so the row updates as you drag down
, array on sheet1 that you are looking up on - this will change depending on your data table
, column() will output the column number thereby giving the column in your array you want to output - will only work if the data headings and cell locations are the exact same
)