[英]Excel find last match from two tables
I'm looking for a way to find the last instance on an entry in the columns A,B and get the corresponding values from columns C,D 我正在寻找一种方法来查找A,B列中条目的最后一个实例,并从列C,D中获取相应的值
In the example below value for Henry is 1374 and value for Amy is 1124 在下面的示例中,Henry的值是1374,Amy的值是1124
Name1 corresponds to Value1 and Name2 corresponds to Value2. Name1对应于Value1,Name2对应于Value2。 Is there a formula to find the last entry from both columns Name1 and Name2 and return the corresponding Value1 or Value2
是否有一个公式可以从Name1和Name2列中找到最后一个条目,并返回相应的Value1或Value2
Raw data pasted below: 粘贴的原始数据如下:
Name1 Name2 Value1 Value2
Sara Amy 1265 1241
John Sara 1142 1214
Amy Henry 1295 1121
Amy John 1175 1323
Sara John 1085 1251
Sara Henry 1242 1374
Amy Sara 1124 1055
Assumptions: 假设:
Data Grid is in cells A1:D8
. 数据网格位于单元格
A1:D8
。 Values "Henry" & "Amy" are in cell A10
& A11
respectively. 值“Henry”和“Amy”分别在单元格
A10
和A11
。
Formula implementation: 公式实施:
In cell B10
following formula is implemented. 在单元格
B10
中实施以下公式。
Alternative 1: 备选方案1:
=INDEX($C$2:$D$8,MAX(IFERROR(LOOKUP(2,1/($A$2:$A$8=A10),ROW($A$2:$A$8)),-1),IFERROR(LOOKUP(2,1/($B$2:$B$8=A10),ROW($B$2:$B$8)),-1))-1,IF(IFERROR(LOOKUP(2,1/($A$2:$A$8=A10),ROW($A$2:$A$8)),-1)>IFERROR(LOOKUP(2,1/($B$2:$B$8=A10),ROW($B$2:$B$8)),-1),1,2))
Alternative 2 (slightly shorter than 1): 备选方案2(略短于1):
=INDEX($C$2:$D$8,LOOKUP(2,1/SEARCH(A10&",",$A$2:$A$8&","&$B$2:$B$8&",",1),ROW($A$2:$A$8))-1,IF(IFERROR(LOOKUP(2,1/($A$2:$A$8=A10),ROW($A$2:$A$8)),-1)>IFERROR(LOOKUP(2,1/($B$2:$B$8=A10),ROW($B$2:$B$8)),-1),1,2)).
To be copied down as much needed. 要尽可能地复制下来。
Notice -1 value after MAX()
function which is used to adjust row number. 注意
MAX()
函数后的-1值,用于调整行号。 It should be always n-1 considering data starts at nth row. 考虑到数据从第n行开始,它应该总是n-1。
Slightly shorter: 略短:
= INDEX($C$1:$D$8,MAX(IF($A$1:$B$8=A10,ROW($A$1:$B$8))),MATCH(A10,
INDEX($A$1:$B$8,MAX(IF($A$1:$B$8=A10,ROW($A$1:$B$8))),0),0))
Note this is an array formula, so you must press Ctrl + Shift + Enter rather than just Enter after typing the formula. 请注意,这是一个数组公式,因此您必须在键入公式后按Ctrl + Shift + Enter而不是按Enter键 。
See below for working example. 请参阅下面的工作示例。
I've been trying to remember another method I've seen for 2d lookup (I can't find the link any more). 我一直在努力记住另一种我见过2d查找的方法(我找不到链接了)。 It's basically like this
它基本上就是这样
=INDIRECT(TEXT(MAX((ROW($A$2:$B$8)*100+COLUMN($A$2:$B$8))*($A$2:$B$8=A10))+2,"R0C00"),FALSE)
entered as an array formula using Ctrl Shift Enter . 使用Ctrl Shift Enter作为数组公式输入 。
So the idea is that you generate a number from the row and column where the last occurrence of the name is located (so for Henry it would be 702). 因此,我们的想法是从名称的最后一次出现的行和列生成一个数字(因此对于Henry来说,它将是702)。
The you format it to give R7C02 and feed this in to an indirect to give the reference to the cell in RC notation. 您将其格式化为R7C02并将其输入到间接,以RC表示法提供对单元格的引用。 The column plus 2 gives the cell that you want.
列加2给出了您想要的单元格。
You might notice that this would fail if column>99, but you can make the multiplier as big as you want. 您可能会注意到,如果列> 99,则会失败,但您可以根据需要调整乘数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.