简体   繁体   中英

How can I search for a substring within a cell array and return the whole string in that cell?

I'm going nuts searching for a way of doing this while using Excel functions.

Need to search a substring within a cell array and get returned the whole string of that cell.

Any ideas?

The problem is the cell array. You can search a single cell with FIND

 =(IF(IFERROR(FIND("AB",A4),0)>0,(A4),""))

will search A4 for the substring "AB" and return either the cell contents or null string. I think you'd need to write a UDF to get it to operate on a cell array

  Public Function SearchCells(RangeToSearch As Range, TextToFind As String) As String
  Dim r As Range
  Dim a As String
  For Each r In RangeToSearch
     If InStr(r.Text, TextToFind) > 0 Then
        a = r.Text
        Exit For
    End If
  Next r
  SearchCells = a
  End Function

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