【问题标题】:How can I search for a substring within a cell array and return the whole string in that cell?如何在单元格数组中搜索子字符串并返回该单元格中的整个字符串?
【发布时间】:2019-09-15 10:49:18
【问题描述】:

我正在发疯地寻找一种在使用 Excel 函数时执行此操作的方法。

需要在单元格数组中搜索子字符串并返回该单元格的整个字符串。

有什么想法吗?

【问题讨论】:

    标签: arrays excel search substring


    【解决方案1】:

    问题在于元胞数组。您可以使用 FIND 搜索单个单元格

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

    将在 A4 中搜索子字符串“AB”并返回单元格内容或空字符串。我认为您需要编写一个 UDF 才能使其在元胞数组上运行

      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
    

    【讨论】:

    • 完全忘记了创建自己的函数......当 excel/VBA 只是我日常活动中不时需要的帮助工具时,就会发生这种情况! :)
    • 我一到办公室就试一试。感谢您的帮助!
    猜你喜欢
    • 2018-07-13
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    • 2021-02-17
    • 2021-09-27
    相关资源
    最近更新 更多