7

我正在尝试将工作表 1 中的 a 列与工作表 2 中的 a 列进行比较,然后将 b 列中的相应值从工作表 1 复制到工作表 2 中的 b 列(其中 a 列的值匹配)。我一直在尝试阅读如何做到这一点,但我不确定我是否应该尝试创建一个宏,或者是否有更简单的方法来做到这一点,也许是 VLOOKUP 或 MATCH?我真的不熟悉这些功能是如何工作的。

此外,如果有所不同,表 2 的 b 列中将出现重复值。

表 1

12AT8001    1
12AT8002    2
12AT8003    3
12AT8004    4
12AT8005    5
12AT8006    6

表 2

12AT8001
12AT8001
12AT8001
12AT8001
12AT8001
12AT8002
12AT8002
12AT8002
12AT8002
12AT8002
12AT8003
12AT8003
12AT8003
12AT8003
12AT8003
4

4 回答 4

5

Vlookup如果参考值(A 列,第 1 页)按升序排列,则很好。另一个选项是索引和匹配,无论顺序如何都可以使用(只要 a 列中的值,工作表 1 是唯一的)

这就是您将在表 2 的 B 栏中输入的内容

=INDEX(Sheet1!A$1:B$6,MATCH(A1,Sheet1!A$1:A$6),2)

设置Sheet1!A$1:B$6Sheet1!A$1:A$6命名范围使其更加用户友好。

于 2012-04-17T15:31:47.577 回答
3

As kmcamara discovered, this is exactly the kind of problem that VLOOKUP is intended to solve, and using vlookup is arguably the simplest of the alternative ways to get the job done.

In addition to the three parameters for lookup_value, table_range to be searched, and the column_index for return values, VLOOKUP takes an optional fourth argument that the Excel documentation calls the "range_lookup".

Expanding on deathApril's explanation, if this argument is set to TRUE (or 1) or omitted, the table range must be sorted in ascending order of the values in the first column of the range for the function to return what would typically be understood to be the "correct" value. Under this default behavior, the function will return a value based upon an exact match, if one is found, or an approximate match if an exact match is not found.

If the match is approximate, the value that is returned by the function will be based on the next largest value that is less than the lookup_value. For example, if "12AT8003" were missing from the table in Sheet 1, the lookup formulas for that value in Sheet 2 would return '2', since "12AT8002" is the largest value in the lookup column of the table range that is less than "12AT8003". (VLOOKUP's default behavior makes perfect sense if, for example, the goal is to look up rates in a tax table.)

However, if the fourth argument is set to FALSE (or 0), VLOOKUP returns a looked-up value only if there is an exact match, and an error value of #N/A if there is not. It is now the usual practice to wrap an exact VLOOKUP in an IFERROR function in order to catch the no-match gracefully. Prior to the introduction of IFERROR, no matches were checked with an IF function using the VLOOKUP formula once to check whether there was a match, and once to return the actual match value.

Though initially harder to master, deusxmach1na's proposed solution is a variation on a powerful set of alternatives to VLOOKUP that can be used to return values for a column or list to the left of the lookup column, expanded to handle cases where an exact match on more than one criterion is needed, or modified to incorporate OR as well as AND match conditions among multiple criteria.

Repeating kcamara's chosen solution, the VLOOKUP formula for this problem would be:

   =VLOOKUP(A1,Sheet1!A$1:B$600,2,FALSE)
于 2013-01-20T02:03:16.813 回答
0

制作一个真值表并使用 SUMPRODUCT 获取值。将其复制到 Sheet2 上的单元格 B1 并根据需要向下复制:
=SUMPRODUCT(--($A1 = Sheet1!$A:$A), Sheet1!$B:$B)
创建真值表的部分是:
--($A1 = Sheet1!$A:$A)
这将返回一个 0 和 1 的数组。值匹配时为 1,不匹配时为 0。然后之后的逗号基本上会执行我所说的“有趣”矩阵乘法并返回结果。不过,我可能误解了您的问题,Sheet1 的 A 列中是否有重复值?

于 2012-04-17T15:50:00.353 回答
-1

尝试:

sheet 2 a1 =vlookup(sheet2a1,sheet1$a$1:$b$6,2)

然后拖下来。

它应该工作。

于 2012-09-06T23:36:07.297 回答