我在工作簿中有两个Excel工作表,如下所示
表格1和2:
以下是两张纸之间的字段关系
我想将EID与EmID进行比较。如果匹配,则对DepID和DependentID进行另一个比较。如果DepID为空白,则将DepDOB与DependentDOB进行比较。当所有这些都成立时,从Sheet2中获取DependentFirstName和DependentLastName并将其复制到Sheet 1中的新列中。
请参阅下面的图片以获得我的预期结果。
输出:
请提供一种实现此目的的方法。如果必须将VLOOKUP和IF结合使用,请告诉我该公式。这给了我噩梦:(
A simple way to do this in the manner your requested is with helper columns. Lets say sheet 1 looks like your output example, with columns A:F shown, and sheet 2 is also showing A:F. Say we use column G for the helper column on each sheet.
The helper column concatenates the three comparison values. So on each sheet, G2 would contain:
=A2&E2&F2
Copy the formula down the column on each sheet. Then compare these values to find the record you need.
VLOOKUP requires that the lookup column be the leftmost in the array. You can accomplish the same style of lookup using INDEX plus MATCH, which doesn't have this limitation. Sheet 1, C2 would contain:
=INDEX(sheet2!B:C,MATCH(G2,sheet2!G:G,0),1)
and in D2:
=INDEX(sheet2!B:C,MATCH(G2,sheet2!G:G,0),2)
Copy these down the column. MATCH finds the key that matches the row on sheet 2 and returns the corresponding names.
如果不想看到帮助者列,则可以隐藏它们。如果您好奇为什么与DepDOB关联的键看起来不像日期,那是因为它使用Excel用于存储日期的内部表示形式。
在这种情况下,您具有填写记录中已包含的名字和姓氏字段所需的所有信息。您可以仅分析DepName字段,而不是使用帮助程序列和查找。C2为:
=LEFT(B2,FIND(" ",B2)-1)
和D2将是:
=RIGHT(B2,LEN(B2)-FIND(" ",B2))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句