简体   繁体   中英

Vlookup with multiple values

So, i have a table, with a several modules in the first column and in the second column the different processes existing in that module. It looks something like this:

图片

Now I have created a data validation list of the unique unique modules, so a list with Module A, Module B, and Module C. When I select a module from that list, I want all the processes, belonging to the module to appear next to the dropdown list in separate cells. It would be a 'nice-to-have' if the processes appear underneath each other.

I have tried various things with index and vlookup etcetera, but I cannot find a way to fix it.

If you have Office 365 Excel then use this array formula:

=TEXTJOIN(",",TRUE,IF($A$2:$A$7 = D2,$B$2:$B$7,""))

This is an array formula and needs to be confirmed with Ctrl-Shift-Enter when exiting edit mode. If done correctly then excel will put {} around the formula.

在此处输入图片说明


If you do not have Office 365 Excel then put this code in a module attached to the workbook and use as described above.

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

To get them to appear in separate cells one below the other use this formula in the first cell and copy down enough to cover the longest list:

=IFERROR(INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$7)/($A$2:$A$7=$D$2),ROW(1:1))),"")

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM