如何在excel中查找包含给定子string的单元格中的所有string

在Excel表格中,每个单元格包含多个string。 我想查找包含给定子string的所有string。 在另一个单元格中打印所有包含子string的string的公式是什么?

例如:

A1-> india china japan In A2, i have to print the strings that contains the substring "in" in A1 A2-> india china 

作为替代,你可以使用这个UDF:

 Public Function GETMATCHES(ByVal strOriginal As String, ByVal strMatch As String) As String GETMATCHES = Join(Filter(Split(WorksheetFunction.Trim(strOriginal), " "), strMatch), " ") End Function 

然后在单元格A2将这个公式: =GETMATCHES(A1,"in")

我担心你不能用标准的Excel工作表函数来做到这一点。 你必须像这样在VBA中编写自己的macros。

 Function matches(ByRef rngCell As Range, ByVal strSearch As String) As String Dim astrWords As Variant Dim strWord As Variant Dim strResult As String 'Get the value from the cell and split into words based on the space seperator astrWords = Split(CStr(rngCell.Value), " ") strResult = "" 'Loop through the words and check if it contains the string that is searched for For Each strWord In astrWords If InStr(strWord, strSearch) Then 'Add it to the result if a match is found If strResult <> "" Then 'Add a space when a previous match was found strResult = strResult & " " End If strResult = strResult & strWord End If Next strWord 'Return the result matches = strResult End Function 

作为一个例子,你可以使用单元格A2中的函数

 =matches(A1;"in")