[英]Excel issue with Function VLOOKUP
I know this might not be the best place to ask a purely excel question, but. 我知道这可能不是问一个纯Excel问题的最佳位置。 I have a table with the following headers: Number, Date, Name. 我有一个带有以下标题的表:数字,日期,名称。 In another file I need to link the number with the name. 在另一个文件中,我需要将数字与名称链接起来。 It is not always in the same order, hence the VLOOKUP formula. 它的顺序并不总是相同,因此是VLOOKUP公式。 Here is the data below. 这是下面的数据。
1 15-Nov Allen 15-Nov
10 15-Nov Allen 15-Nov
19 15-Nov Allen 15-Nov
6 5-Mar Avalon 5-Mar
15 5-Mar Avalon 5-Mar
24 5-Mar Avalon 5-Mar
9 15-Nov Burg 15-Nov
18 15-Nov Burg 15-Nov
27 15-Nov Burg 15-Nov
8 1-Sep Fischer 1-Sep
17 1-Sep Fischer 1-Sep
26 1-Sep Fischer 1-Sep
3 14-Oct Kiser 14-Oct
12 14-Oct Kiser 14-Oct
21 14-Oct Kiser 14-Oct
2 15-Oct Remmert 15-Oct
11 15-Oct Remmert 15-Oct
20 15-Oct Remmert 15-Oct
4 1-Sep Roos 1-Sep
13 1-Sep Roos 1-Sep
22 1-Sep Roos 1-Sep
7 6-Feb Tomo 6-Feb
16 6-Feb Tomo 6-Feb
25 6-Feb Tomo 6-Feb
5 1-Jan Wash 1-Jan
14 1-Jan Wash 1-Jan
23 1-Jan Wash 1-Jan
So Lets assume it is titled as Column A, B, C, D. So in the new file in order to grab the name from numbers I used the formula: 因此,让我们假设其标题为A,B,C,D列。因此在新文件中,为了从数字中获取名称,我使用了公式:
=VLOOKUP(A1,[Workbook1]Sheet1!$A$1:$D$27,3,FALSE)
Workbook1 and Sheet1 is where the data is. 数据所在的位置是Workbook1和Sheet1。 Next I need to grab the date from the file by linking it to the name. 接下来,我需要通过链接到名称来从文件中获取日期。 I know I can link it to the number but it is a thing for work and the way they are arranged are with Different dates from oldest to newest, not the same like this one. 我知道我可以将其链接到数字,但这是工作的事情,而且它们的排列方式从最早到最新的日期是不同的,而不是像这样的日期。 The Date function in excel is extremely stupid in my opinion. 我认为Excel中的Date函数非常愚蠢。 So I used the formula 所以我用公式
=VLOOKUP(B1,[Workbook1]Sheet1!$A$1:$D$27,1,FALSE)
and iterations of it by replacing the 1 with 4. It keeps returning N/A. 并通过将1替换为4来进行迭代。它不断返回N / A。 Even when I change the formatting of the Date to General it still returns nothing. 即使我将“日期”的格式更改为“常规”,它仍然不会返回任何内容。 I dont get what I am doing wrong here. 我不明白我在做什么错。
I assume that B1 holds the name of the person. 我假设B1拥有此人的名字。 In that case, you need to adjust the range for the lookup table, so that it starts in the column with the name, ie 在这种情况下,您需要调整查找表的范围,以便它以名称(即
=VLOOKUP(B1,[Workbook1]Sheet1!$C$1:$D$27,2,FALSE)
EDITTED : Change the column to 2 to get the date 编辑:将列更改为2以获取日期
VLOOKUP syntax: VLOOKUP语法:
VLOOKUP ( lookup_value , table_array, col_index_num, (optional) [range_lookup] ) VLOOKUP ( lookup_value,table_array,col_index_num,(可选)[range_lookup] )
The VLOOKUP function will always look up the lookup_value in the first column of the table_array . VLOOKUP函数将始终在table_array的第一列中查找lookup_value 。 It then attempts to return the value in the col_index_num of the corresponding row in the table_array . 然后,它尝试返回table_array中相应行的col_index_num中的值 。 The range_lookup tells VLOOKUP whether to look for an exact or an approximate match. range_lookup告诉VLOOKUP是寻找完全匹配还是近似匹配。 In your case, you will be looking for an exact match. 在您的情况下,您将寻找完全匹配的内容。
In no way can VLOOKUP return a value in the table_array that is to the left of the column looking to match the lookup_value . VLOOKUP绝对不能在table_array中返回要与lookup_value匹配的列左侧的值。 The lookup_value is always looked for in the first column and VLOOKUP returns a value in a column to the right. 总是在第一列中查找lookup_value ,而VLOOKUP在右侧的列中返回一个值。
Your formula to look up the name based upon the ID number in column A works well for this. 您可以根据A列中的ID号来查找名称的公式对此效果很好。
=VLOOKUP(A1, [Workbook1]Sheet1!$A$1:$D$27, 3, FALSE)
With 8 in A1, the above formula returns Fischer in B1. 在A1中为8时,以上公式将在B1中返回Fischer 。
When you are looking to return the dates, VLOOKUP will work for the one to the right of the name in Sheet1's column D but it cannot the return the date from Sheet1's column B basing the lookup_value on the name. 当您希望返回日期时,VLOOKUP将适用于Sheet1的D列中名称右侧的那个,但它不能基于名称的lookup_value返回Sheet1的B列中的日期。 You will need an INDEX / MATCH function pair for that. 为此,您将需要一个INDEX / MATCH函数对。 In addition, retrieving the second and third date sets that match the name is easier with INDEX/MATCH than VLOOKUP. 另外,使用INDEX / MATCH检索与名称匹配的第二和第三日期集比使用VLOOKUP容易。
INDEX and MATCH syntax: INDEX和MATCH语法:
INDEX ( array, row_num, column_num ) INDEX ( 数组,row_num,column_num )
MATCH ( lookup_value, lookup_array, (optional) [match_type] ) 匹配 ( lookup_value,lookup_array,(可选)[match_type] )
If you are looking to return the date from Sheet1's column B using the name just retrieved from Sheet1's column C, you will have to use an INDEX/MATCH pair. 如果希望使用从Sheet1的C列中检索到的名称从Sheet1的B列返回日期,则必须使用INDEX / MATCH对。 Since we are using this for one date, it is eaay to use it for the other although strictly speaking, VLOOKUP could be used for this. 由于我们将它用于一个日期,所以很容易将其用于另一个日期,尽管严格来讲, 可以将VLOOKUP用于此日期。
Use these two formulas in C1 and D1. 在C1和D1中使用这两个公式。
=INDEX([Workbook1]Sheet1!B:B, MATCH(B1, [Workbook1]Sheet1!C:C, 0))
=INDEX([Workbook1]Sheet1!D:D, MATCH(B1, [Workbook1]Sheet1!C:C, 0))
Format the cells for a custom number format of d-mmm . 将单元格格式化为d-mmm的自定义数字格式。 Your results should be similar to the following. 您的结果应类似于以下内容。
If you wanted to return the second and third dates from Sheet1 that match the name in column B, change the target worksheet's C1 and D1 to to these formulas that use the SMALL function togewther with the ROW function and COUNTIF function to produce the additional dates. 如果要从Sheet1中返回与B列中的名称匹配的第二个和第三个日期,请将目标工作表的C1和D1更改为这些公式,这些公式使用SMALL函数与ROW函数和COUNTIF函数结合在一起以产生其他日期。
Make a minor tweak to the formula in B1 so it can be filled down then supply the next two formulas for C1 and D1. 对B1中的公式进行较小的调整,以便可以对其进行填充,然后为C1和D1提供接下来的两个公式。
=VLOOKUP(A$1, [Workbook1]Sheet1!$A$1:$D$27, 3, FALSE)
=IFERROR(INDEX([Workbook1]Sheet1!B$1:B$999, SMALL(INDEX(ROW($1:$999)+([Workbook1]Sheet1!C$1:C$999<>B$1)*1E+99, , ), COUNTIF(B$1:B1, B1))), "")
=IFERROR(INDEX([Workbook1]Sheet1!B$1:B$999, SMALL(INDEX(ROW($1:$999)+([Workbook1]Sheet1!C$1:C$999<>B$1)*1E+99, , ), COUNTIF(B$1:B1, B1))), "")
Fill B1:D1 down down to catch all of the possible dates from Sheet1 that match the name returned from your original ID lookup. 向下填充B1:D1,以捕获Sheet1中与原始ID查找返回的名称匹配的所有可能日期。 Your results should look like, 您的结果应如下所示:
You may notice that I sequenced the identical dates on Sheet1 in order to demonstrate the method. 您可能会注意到,为了演示该方法,我在Sheet1上对相同的日期进行了排序。 The IFERROR function is used to display an empty string (eg "") instead of an error message when you run out of values (as in C4 and D4 in the above sample image). 当值用完时(如上面的示例图像中的C4和D4所示), IFERROR函数用于显示空字符串(例如““)而不是错误消息。
In summary, use the VLOOKUP function to return values to the right of the value sought; 总而言之,使用VLOOKUP函数将值返回到所寻找值的右边。 use an INDEX / MATCH function pair to retrieve values from either side of the matching column. 使用INDEX / MATCH函数对从匹配列的任一侧检索值。
You need format the date with the following format : 您需要使用以下格式来格式化日期:
This is the overall that I had done to solve the problem. 这是我为解决问题所做的总体工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.