简体   繁体   中英

EXCEL MATCH: Return 1 match from multiple criteria within 1 cell

Example Screenshot Let's say column 1 has IDs and column 2&3 have descriptions. Multiple values in Column 2&3 have LCD descriptions but I am looking for a match that has LCD,TCD and MCD and all of these values are in the same cell [regardless of if extra values also exist in that cell]. How would I go about returning the ID(from column 1) for the one combination that is LCD + TCD + MCD (from column 2&3) in column 4[given that the some of these values exist in other cells but I do not want these other cell values returned, I want a match to the multiple criteria within ONE cell NOT values across multiple cells]?

Thanks!

假设您有上述表格中的数据

In description column for IDs A and B we have LCD,MCD and TCD available and you want IDs A and B in column 3 and no for row number 4 because we have only TCD there. If so you can use below formula else provide a sample of your data :

=IF(AND(ISNUMBER(SEARCH("LCD",B2)),ISNUMBER(SEARCH("MCD",B2)),ISNUMBER(SEARCH("TCD",B2))),A2,"No")

If you are interested to use VBA try:

Option Explicit

Sub Sample()

    Dim Lastrow As Long, i As Long, y As Long, Times As Long
    Dim arr As Variant

    With ThisWorkbook.Worksheets("Sheet1")

        Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row

        For i = 3 To Lastrow

            arr = Split(.Range("B" & i), " ")

            Times = 0

             For y = LBound(arr, 1) To UBound(arr, 1)

                If InStr(1, .Range("C" & i).Value, arr(y)) > 0 Then

                    Times = Times + 1

                End If

            Next y

            If Times = UBound(arr) + 1 Then
                .Range("D" & i).Value = .Range("A" & i).Value
            End If

        Next i

    End With

End Sub

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