一、只需要用vlookup在一列中查找值,返回true或false(是或否),而不是返回匹配到的值。
采用以下公式:=IF(ISNA(VLOOKUP(目标值, $D:$E, 1, FALSE)), "否", "是")
原理是,VLOOKUP如果匹配不成功,则返回“#NA”,所以用ISNA函数判断返回值是否#NA即可。
二、Vlookup使用数组公式从多个列返回匹配值
从多个列中选择要在其中放置匹配值的单元格(假设3个格子), 然后输入以下公式: =VLOOKUP(目标值,$A:$E, {2,4,5}, FALSE) 进入编辑栏,然后按 Ctrl + Shift + Enter 键在一起,并且一次提取了多个列的匹配值。
或者输入以下公式: = VLOOKUP(目标值,$A:$D, COLUMN(A1), FALSE) 放入要获取结果的空白单元格,然后将公式向右拖动。
三、通过vlookup返回多个值
通常,在Excel中使用VLOOKUP函数时,如果有多个值与条件匹配,则只返回匹配结果的第一个。Excel 2019和Office 365下Vlookup可以使用TEXTJOIN函数将符合条件的所有相应值返回到一个单元格中。
而低版本的Excel则需要借助VBA宏实现:
'VBA代码:Vlookup将多个值返回到一个单元格
Function ConcatenateIf(CriteriaRange As Range, Condition As Variant, ConcatenateRange As Range, Optional Separator As String = ",") As Variant
'Updateby Extendoffice
Dim xResult As String
On Error Resume Next
If CriteriaRange.Count <> ConcatenateRange.Count Then
ConcatenateIf = CVErr(xlErrRef)
Exit Function
End If
For i = 1 To CriteriaRange.Count
If CriteriaRange.Cells(i).Value = Condition Then
xResult = xResult & Separator & ConcatenateRange.Cells(i).Value
End If
Next i
If xResult <> "" Then
xResult = VBA.Mid(xResult, VBA.Len(Separator) + 1)
End If
ConcatenateIf = xResult
Exit Function
End Function
VBA代码:Vlookup并将多个唯一匹配的值返回到一个单元格中
Function MultipleLookupNoRept(Lookupvalue As String, LookupRange As Range, ColumnNumber As Integer)
'Updateby Extendoffice
Dim xDic As New Dictionary
Dim xRows As Long
Dim xStr As String
Dim i As Long
On Error Resume Next
xRows = LookupRange.Rows.Count
For i = 1 To xRows
If LookupRange.Columns(1).Cells(i).Value = Lookupvalue Then
xDic.Add LookupRange.Columns(ColumnNumber).Cells(i).Value, ""
End If
Next
xStr = ""
MultipleLookupNoRept = xStr
If xDic.Count > 0 Then
For i = 0 To xDic.Count - 1
xStr = xStr & xDic.Keys(i) & ","
Next
MultipleLookupNoRept = Left(xStr, Len(xStr) - 1)
End If
End Function
参考资料:https://zh-cn.extendoffice.com/documents/excel/2706-excel-vlookup-return-multiple-values-in-one-cell.html
标签:Count,Function,End,技巧,匹配,vlookup,Excel,xStr,xResult From: https://www.cnblogs.com/GuominQiu/p/17075812.html