简体   繁体   中英

Excel: Check for partial matches from column against single cell

I have two columns in Excel:

      Column A
Row 1 Apple
Row 2 Blueberry
Row 3 Strawberry

      Column B
Row 1 App
Row 2 Application
Row 3 Appendage

I would like to use Column B to see if any cells within it exist within the given cell in Column A. So far, I have used the VLOOKUP and MATCH functions and I can't seem to get either to work properly, but MATCH seems to be the one I should be using. I tried using wildcards on Column B and it returns a value error. Here is what I have:

=MATCH(A1,"*"&B:B&"*",0)

Your help is greatly appreciated!

There is a natural VBA solution. In a standard code module place:

Function PartialMatch(v As Variant, R As Range) As Variant
    Dim i As Long
    For i = 1 To R.Cells.Count
        If v Like "*" & R.Cells(i).Value & "*" Then
            PartialMatch = i
            Exit Function
        End If
    Next i
    PartialMatch = CVErr(xlErrNA)
End Function

Then where you want it in a spreadsheet you can use the formula:

=PartialMatch(A1,B:B)

It will give the index of the first partial match, if any exists, or #N/A if it doesn't. Note that a blank cell counts as a partial match, so you might want to make sure that the range that you pass the function contains no blanks (so don't pass the whole column). That, or redefine what you mean by a partial match.

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