Look Values in column 1 and bring column 2 values

后端 未结 3 1015
[愿得一人]
[愿得一人] 2020-12-11 14:39

my data set looks like

Col A   
A/05702; A/05724; A/05724;A/05724;A/05725;A/05725;
corresponding Col B
1;1;2;3;1;3;

I am trying to get the

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 14:57

    You can use this simple UDF:

    Function TEXTJOIN(delim As String, skipblank As Boolean, arr) As String
        Dim d
        For Each d In arr
            If d <> "" Or Not skipblank Then
                TEXTJOIN = TEXTJOIN & d & delim
            End If
        Next d
        TEXTJOIN = Left(TEXTJOIN, Len(TEXTJOIN) - 1)
    End Function
    

    Make sure to put it in a module attached to the desired workbook and NOT in the worksheet code or in ThisWorkbook code.

    It is then called like this:

    =TEXTJOIN(",",TRUE,IF($A$1:$A$6 = $C1, $B$1:$B$6, ""))
    

    Entered as an Array formula with Ctrl-Shift-Enter. If done correctly Excel will put {} around the formula.


    NOTE

    If you have Office 365 the UDF is not needed as it exists in Excel, Just enter the formula as an array.


    Alternative

    If you want a formula only approach AND your data is sorted then you will need a "helper column". I put mine in Column C. In C1 I put:

    =IF(A2<>A1,B1,B1&"," &C2)
    

    Which gave me:

    Then a simple VLOOKUP will return what we want:

    =VLOOKUP(E1,A:C,3,FALSE)
    

提交回复
热议问题