Excel issue with Function VLOOKUP

后端 未结 3 1532
时光取名叫无心
时光取名叫无心 2020-12-12 04:45

I know this might not be the best place to ask a purely excel question, but. I have a table with the following headers: Number, Date, Name. In another file I need to link th

相关标签:
3条回答
  • 2020-12-12 05:22

    VLOOKUP syntax:

    VLOOKUP(lookup_value , table_array, col_index_num, (optional) [range_lookup])

    The VLOOKUP function will always look up the lookup_value in the first column of the table_array. It then attempts to return the value in the col_index_num of the corresponding row in the table_array. The range_lookup tells VLOOKUP whether to look for an exact or an approximate match. 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. The lookup_value is always looked for in the first column and VLOOKUP returns a value in a column to the right.

    Your formula to look up the name based upon the ID number in column A works well for this.

    =VLOOKUP(A1, [Workbook1]Sheet1!$A$1:$D$27, 3, FALSE)
    

    With 8 in A1, the above formula returns Fischer in B1.

          VLOOKUP vs INDEX/MATCH

    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. You will need an INDEX/MATCH function pair for that. In addition, retrieving the second and third date sets that match the name is easier with INDEX/MATCH than VLOOKUP.

    INDEX and MATCH syntax:

    INDEX(array, row_num, column_num)

    MATCH(lookup_value, lookup_array, (optional) [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. 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.

    Use these two formulas in C1 and 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. Your results should be similar to the following.

          VLOOKUP vs INDEX/MATCH

    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.

    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.

    =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. Your results should look like,

          VLOOKUP vs INDEX/MATCH

    You may notice that I sequenced the identical dates on Sheet1 in order to demonstrate the method. The IFERROR function is used to display an empty string (e.g. "") instead of an error message when you run out of values (as in C4 and D4 in the above sample image).

    In summary, use the VLOOKUP function to return values to the right of the value sought; use an INDEX/MATCH function pair to retrieve values from either side of the matching column.

    0 讨论(0)
  • 2020-12-12 05:35

    You need format the date with the following format :
    Date format
    This is the overall that I had done to solve the problem. Overall

    0 讨论(0)
  • 2020-12-12 05:47

    I assume that B1 holds the name of the person. In that case, you need to adjust the range for the lookup table, so that it starts in the column with the name, i.e.

    =VLOOKUP(B1,[Workbook1]Sheet1!$C$1:$D$27,2,FALSE)
    

    EDITTED : Change the column to 2 to get the date

    0 讨论(0)
提交回复
热议问题