Check whether a cell contains a substring

前端 未结 9 1683
闹比i
闹比i 2020-11-30 17:41

Is there an in-built function to check if a cell contains a given character/substring?

It would mean you can apply textual functions like Left/R

9条回答
  •  被撕碎了的回忆
    2020-11-30 18:02

    It's an old question but I think it is still valid.

    Since there is no CONTAINS function, why not declare it in VBA? The code below uses the VBA Instr function, which looks for a substring in a string. It returns 0 when the string is not found.

    Public Function CONTAINS(TextString As String, SubString As String) As Integer
        CONTAINS = InStr(1, TextString, SubString)
    End Function
    

提交回复
热议问题