2014-10-08 3 views
0

Excel 시트에서 각 셀에는 둘 이상의 문자열이 포함되어 있습니다. 주어진 하위 문자열을 포함하는 모든 문자열을 찾고 싶습니다. 다른 셀의 하위 문자열을 포함하는 모든 문자열을 인쇄하는 수식은 무엇입니까?주어진 하위 문자열이있는 셀의 모든 문자열을 찾는 방법

예컨대 :

A1-> india china japan 

    In A2, i have to print the strings that contains the substring "in" in A1 

    A2-> india china 

답변

1

으로 A2 셀의 기능을 사용할 수 있습니다 예를 들어

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 

, 당신은이 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")

+0

고마워 .. 그게 효과가 ... –

0

난 당신이 그렇게 할 수 없습니다 두려워 표준 Excel 워크 시트 기능. 이런 식으로 VBA에서 직접 매크로를 작성해야합니다. 당신이 다른 것처럼

=matches(A1;"in") 
+0

코드 주셔서 감사합니다. –

관련 문제