Vlookup使用2列引用另一列 [英] Vlookup using 2 columns to reference another

查看:311
本文介绍了Vlookup使用2列引用另一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个名字前做一个vlookup来获得一个年龄。这将在列A,然后列B中完成。如果在列A中找到,继续到列B,如果在列B中找到,则将来自列C的J3中的年龄设置为无。



这里是一个例子:

  J1 = John 
J2 = Doe
J3 = = VLOOKUP J1& J2,A1:C50,3,FALSE)

J3是我到目前为止。为了获得年龄,我需要嵌套一个Vlookup来检查列A,然后是列B?



这是表格列表的一个例子:

  ABC 
Jeff Vel 80
John Fly 25
Jake Foo 20
John Doe 55

J3 = 55。

解决方案许多方法:


  1. 处理数字返回:

如果你的返回值是数字,并且匹配是唯一的(数据中只有一个John Doe),或者如果有多个则要求返回值,那么使用SUMIFS是最快的方法。

  = SUMIFS(C:C,A:A,J1,B:B,J2)







  1. 带非数字返回

如果回报不是数字或有多个,那么有两种方法来获得列表中的第一个匹配项:



a。帮助列:



在第四列中输入以下公式:

  = A1& B1 

并复制列表





然后使用INDEX / MATCH:

  = INDEX(C:C,MATCH(J1& J2,D:D,0))



b。数组公式:



如果您不想或无法创建第四列,则使用数组类型公式:

  = INDEX(C:C,AGGREGATE(15,6,ROW($ A $ 1:$ A $ 4)/(($ A $ 1:$ A $ 4 = J1)*($ B $ 1:$ B $ 4 = J2)),1))

数组类型公式需要限制





如果您的数据集定期更改大小,可以通过添加更多的INDEX / MATCH来将上述内容修改为动态,以返回最后一个单元格的数据:

  = INDEX(C:C,AGGREGATE(15,6,ROW($ A $ 1:INDEX($ A:$ A,MATCH( ZZZ,A:A)))/(($ A $ 1: INDEX($ A:$ A,MATCH( ZZZ,A:A))= J1)*($ B $ 1:INDEX($ B:$ B,MATCH( ZZZ,A:A))= J2) ),1))

这将允许数据集增长或缩小,公式只会迭代通过那些有数据而不是t的他的全部列。



上述方法按照Best-Better-Good的顺序设置。







  1. 在一个单元格中获取多个答案

如果您不想求和,或者返回值是文本,并且有多个John Doe实例,并且希望在一个单元格中返回所有值,那么:



一个。如果您有Office 365 Excel,您可以使用数组形式的TEXTJOIN:

  = TEXTJOIN(,,TRUE,IF ($ A $ 1:$ A $ 4 = J1)*($ B $ 1:$ B $ 4 = J2),$ C $ 1:$ C $ 4,))

作为一个数组公式,在退出编辑模式时,需要使用Ctrl-Shift-Enter而不是Enter进行确认。如果正确完成,Excel将围绕公式放置 {}



像上面的AGGREGATE公式一样,它需要限于数据集。范围可以通过INDEX / MATCH函数如上所述而动态化。





b。如果没有Office 365 Excel,则将此代码添加到附加到工作簿的模块中:

 函数TEXTJOIN(delim As String ,skipblank As Boolean,arr)
Dim d As Long
Dim c As Long
Dim arr2()
Dim t As Long,y As Long
t = -1
y = -1
如果TypeName(arr)=Range然后
arr2 = arr.Value
Else
arr2 = arr
End If
On Error Resume Next
t = UBound(arr2,2)
y = UBound(arr2,1)
On Error GoTo 0

如果t> = 0并且y> = 0然后
对于c = LBound(arr2,1)到UBound(arr2,1)
对于d = LBound(arr2,1)到UBound(arr2,2)
如果arr2(c,d) 还是不skipblank然后
TEXTJOIN = TEXTJOIN& arr2(c,d)&如果arr2(c)< ;> 还是不skipblank然后
TEXTJOIN = TEXTJOIN& arr2(c)& delim
End If
Next c
End If
TEXTJOIN = Left(TEXTJOIN,Len(TEXTJOIN) - Len(delim))
结束函数

然后如上所述使用TEXTJOIN()公式。


I am trying to do a vlookup under a circumstance of first then last name to get an age. This will be done within Column A, then Column B. If found in Column A, Continue to Column B, If found in Column B, put age in J3 that comes from Column C else put "None".

Here is an example:

J1 = John
J2 = Doe
J3 = =VLOOKUP J1 & J2,A1:C50,3,FALSE)

J3 is what I have so far. Do I need to nest a Vlookup to check Column A, then Column B in order to get the age?

Here is an example of the table list:

A     B    C
Jeff  Vel  80
John  Fly  25
Jake  Foo  20
John  Doe  55

J3 = 55.

解决方案

Many ways:

  1. Dealing with Number returns:

If your return values are numbers and the match is unique(there is only one John Doe in the data) or you want to sum the returns if there are multiples, then Using SUMIFS is the quickest method.

=SUMIFS(C:C,A:A,J1,B:B,J2)


  1. With non numeric returns

If the returns are not numeric or there are multiples then there are two methods to get the first match in the list:

a. A helper column:

In a forth column put the following formula:

=A1&B1

and copy down the list

Then use INDEX/MATCH:

=INDEX(C:C,MATCH(J1&J2,D:D,0))

b. The array formula:

If you do not want or cannot create the forth column then use an array type formula:

=INDEX(C:C,AGGREGATE(15,6,ROW($A$1:$A$4)/(($A$1:$A$4=J1)*($B$1:$B$4=J2)),1))

Array type formulas need to limit the size of the data to the data set.

If your data set changes sizes regularly we can modify the above to be dynamic by adding more INDEX/MATCH to return the last cell with data:

=INDEX(C:C,AGGREGATE(15,6,ROW($A$1:INDEX($A:$A,MATCH("ZZZ",A:A)))/(($A$1:INDEX($A:$A,MATCH("ZZZ",A:A))=J1)*($B$1:INDEX($B:$B,MATCH("ZZZ",A:A))=J2)),1))

This will allow the data set to grow or shrink and the formula will only iterate through those that have data and not the full column.

The methods described above are set in the order of Best-Better-Good.


  1. To get multiple answers in one cell

If you do not want to sum, or the return values are text and there are multiple instances of John Doe and you want all the values returned in one cell then:

a. If you have Office 365 Excel you can use an array form of TEXTJOIN:

=TEXTJOIN(",",TRUE,IF(($A$1:$A$4=J1)*($B$1:$B$4=J2),$C$1:$C$4,""))

Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.

Like the AGGREGATE formula above it needs to be limited to the data set. The ranges can be made dynamic with the INDEX/MATCH functions like above also.

b. If one does not have Office 365 Excel then add this code to a module attached to the workbook:

Function TEXTJOIN(delim As String, skipblank As Boolean, arr)
    Dim d As Long
    Dim c As Long
    Dim arr2()
    Dim t As Long, y As Long
    t = -1
    y = -1
    If TypeName(arr) = "Range" Then
        arr2 = arr.Value
    Else
        arr2 = arr
    End If
    On Error Resume Next
    t = UBound(arr2, 2)
    y = UBound(arr2, 1)
    On Error GoTo 0

    If t >= 0 And y >= 0 Then
        For c = LBound(arr2, 1) To UBound(arr2, 1)
            For d = LBound(arr2, 1) To UBound(arr2, 2)
                If arr2(c, d) <> "" Or Not skipblank Then
                    TEXTJOIN = TEXTJOIN & arr2(c, d) & delim
                End If
            Next d
        Next c
    Else
        For c = LBound(arr2) To UBound(arr2)
            If arr2(c) <> "" Or Not skipblank Then
                TEXTJOIN = TEXTJOIN & arr2(c) & delim
            End If
        Next c
    End If
    TEXTJOIN = Left(TEXTJOIN, Len(TEXTJOIN) - Len(delim))
End Function

Then use the TEXTJOIN() formula as described above.

这篇关于Vlookup使用2列引用另一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆