[英]Is there a way, using built-in Excel functions only, to check one set of data against another?
More specifically, assume there is a full list of names and addresses on a worksheet. 更具体地说,假定工作表上有完整的名称和地址列表。 There is also a second worksheet with a subset of the names from the full sheet, with newly updated addresses.
还有第二个工作表,其中包含整个工作表中名称的子集,并带有新更新的地址。
Is there a way to loop through all of the names on the full sheet, check if it matches any of the names in the revised sheet, and, if so, update the relevant address on the full sheet with the relevant new address from the second sheet? 有没有一种方法可以遍历整张纸上的所有名称,检查它是否与修订版纸上的任何名称匹配,如果是,则用第二个新的相关新地址更新整张纸上的相关地址。片?
I managed to get it to successfully check the names from sheet1 against the names on sheet2, but I don't know of a way to tell the formula what cells to get the address information from in the event of a match. 我设法使其成功地将工作表1中的名称与工作表2中的名称进行了比较,但是我不知道一种方法来告诉公式在发生匹配时从哪个单元格获取地址信息。
The format of the cells is firstname, lastname, address1, address2, city, state, zipcode for both worksheets. 单元格的格式是两个工作表的名字,姓氏,地址1,地址2,城市,州,邮政编码。
VLOOKUP is the function you are looking for. VLOOKUP是您要寻找的功能。 Once you have mastered this, you might want to look into the INDEX AND MATCH functions, which can achieve the same result more efficiently and (sometimes).
掌握了这一点之后,您可能想研究一下INDEX和MATCH函数,它们可以更有效地(有时)获得相同的结果。
For complete description of VLOOKUP, see Microsoft's support page for VLOOKUP 有关VLOOKUP的完整说明,请参阅Microsoft的VLOOKUP支持页面。
It's very helpful to have a unique id code for each individual. 为每个人设置唯一的ID码非常有帮助。 If you have one, include it in column A of both datasets.
如果有一个,请将其包括在两个数据集的A列中。 If you don't have one, you can construct an ID field, but you'll need to do some manual work to make sure it is unique.
如果您没有,则可以构造一个ID字段,但是您需要做一些手工工作以确保它是唯一的。 (Suggestion on how to go about constructing ID code at end of answer.)
(有关如何在答案结尾处构造ID代码的建议。)
Put the ID in column A. Columns BH will have your other fields, so address1 will be in column D. 将ID放在A列中。BH列将具有您的其他字段,因此address1将在D列中。
You're going to want an absolute reference for your original data. 您将需要原始数据的绝对参考。 Let's call the worksheet with old data Worksheet1 and the one with the new data Worksheet2.
让我们用旧数据Worksheet1调用工作表,用新数据Worksheet2调用工作表。 Then the reference for original data (including ID code) will be Worksheet1!$A:$H
然后原始数据(包括ID码)的引用将为Worksheet1!$ A:$ H
VLOOKUP will match the ID code in new worksheet with the one in the old, and then pull data from the column you specify. VLOOKUP将新工作表中的ID代码与旧工作表中的ID代码匹配,然后从您指定的列中提取数据。 To look up the matching address1 for the first person in the new dataset, you'd use this formula:
要在新数据集中查找第一个人的匹配地址1,请使用以下公式:
=VLOOKUP(A1,Worksheet1!$A:$H,4,0)
where 哪里
Do this once for each column that you want to compare (address2 will look the same as address1, but will reference column 5 instead of column 4). 对要比较的每一列执行一次此操作(address2看起来与address1相同,但是将引用第5列而不是第4列)。 Havind done this, you can copy to the rest of the rows in your new worksheet.
Havind完成了此操作,您可以将其复制到新工作表的其余行中。
Procedure above will pull old data into appropriate row of new worksheet. 上面的过程会将旧数据拉到新工作表的相应行中。 If you just want to know if there is a change to a particular field, you could do something like:
如果您只想知道特定字段是否发生更改,可以执行以下操作:
=IF(D1=VLOOKUP(A1,Worksheet1!$A:$H,4,0),"","changed")
There are obviously lots of ways to refine this and condense the information. 显然,有很多方法可以对此进行改进并压缩信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.