问题描述
在SQL中,我将这样做:
SELECT id,name
FROM Sheet1
INNER JOIN Sheet2
ON Sheet1.id = Sheet2.id;
Sheet1:
code> + ---- + ------ +
| ID |名称|
+ ---- + ------ +
| 1 | A |
| 2 | B |
| 3 | C |
| 4 | D |
+ ---- + ------ +
Sheet2: p>
+ ---- + ----- +
| ID |年龄|
+ ---- + ----- +
| 1 | 20 |
| 2 | 21 |
| 4 | 22 |
+ ---- + ----- +
结果将是:
+ ---- + ------ +
| ID |名称|
+ ---- + ------ +
| 1 | A |
| 2 | B |
| 4 | D |
+ ---- + ------ +
我该怎么办这在VLOOKUP?或者除了VLOOKUP还有更好的方法吗?
谢谢。
首先让我们得到两个表中存在的值的列表。如果您使用的是excel 2010或更高版本,那么在Sheet 3 A2中,输入以下公式:
= IFERROR(AGGREGATE(15,6 !,Sheet 2中$ A $ 1:$ A $ 5000 /(!COUNTIF(Sheet 1中$ A $ 1:$ A $ 5000,Sheet 2中$ A $ 1:$ A $ 5000)大于0),ROW(1:1)), )
如果您使用的是2007或更早版本,请使用此数组公式:
= IFERROR(SMALL(IF(COUNTIF(Sheet1!$ A $ 1:$ A $ 5000,Sheet2!$ A $ 1:$ A $ 5000))Sheet2!$ A $ 1 $ A $ 5000),ROW(1:1)),)
作为数组公式,复制并粘贴到公式栏中,然后按Ctrl-Shift-Enter而不是Enter或Tab退出编辑模式。
然后根据需要复制多行。这将创建两个列表中的ID'd列表。这确实假定ID是一个数字,而不是文本。
然后与该列表我们使用vlookup:
= IF(A2<",VLOOKUP(A2,Sheet1!A:B,2,FALSE),)
pre>
然后,这将返回与Sheet 1匹配的值。
Is there a way to inner join two different Excel spreadsheets using VLOOKUP?
In SQL, I would do it this way:
SELECT id, name FROM Sheet1 INNER JOIN Sheet2 ON Sheet1.id = Sheet2.id;
Sheet1:
+----+------+ | ID | Name | +----+------+ | 1 | A | | 2 | B | | 3 | C | | 4 | D | +----+------+
Sheet2:
+----+-----+ | ID | Age | +----+-----+ | 1 | 20 | | 2 | 21 | | 4 | 22 | +----+-----+
And the result would be:
+----+------+ | ID | Name | +----+------+ | 1 | A | | 2 | B | | 4 | D | +----+------+
How can I do this in VLOOKUP? Or is there a better way to do this besides VLOOKUP?
Thanks.
解决方案First lets get a list of values that exist in both tables. If you are using excel 2010 or later then in Sheet 3 A2 put the following formula:
=IFERROR(AGGREGATE(15,6,Sheet2!$A$1:$A$5000/(COUNTIF(Sheet1!$A$1:$A$5000,Sheet2!$A$1:$A$5000)>0),ROW(1:1)),"")
If you are using 2007 or earlier then use this array formula:
=IFERROR(SMALL(IF(COUNTIF(Sheet1!$A$1:$A$5000,Sheet2!$A$1:$A$5000),Sheet2!$A$1:$A$5000),ROW(1:1)),"")
Being an array formula, copy and paste into the formula bar then hit Ctrl-Shift-Enter instead of Enter or Tab to leave the edit mode.
Then copy down as many rows as desired. This will create a list of ID'd that are in both lists. This does assume that ID is a number and not text.
Then with that list we use vlookup:
=IF(A2<>"",VLOOKUP(A2,Sheet1!A:B,2,FALSE),"")
This will then return the value from Sheet 1 that matches.
这篇关于如何在Excel中进行内部连接(例如使用VLOOKUP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!