• 목록
  • 아래로
  • 위로
  • 쓰기
  • 검색

특정 단어 찾기 최종

  • 만조
  • 14
  • 0

Function findx(searchWords As String, searchCell As Range) As String
    Dim result As String
    Dim startIndex As Integer
    Dim endIndex As Integer
    Dim surroundingText As String
    Dim wordArray() As String
    Dim i As Integer
    
    ' 결과 및 초기 설정
    result = ""
    wordArray = Split(searchWords, ",") ' 쉼표로 구분된 단어들을 배열로 분리

    For i = LBound(wordArray) To UBound(wordArray)
        ' 각 단어에 대해 검색 수행
        startIndex = InStr(1, searchCell.Value, Trim(wordArray(i)), vbTextCompare)

        ' 찾을 단어가 존재하는 경우
        If startIndex > 0 Then
            ' 찾은 단어의 앞뒤 10글자의 시작 및 끝 인덱스 계산
            endIndex = startIndex + Len(wordArray(i)) - 1
            startIndex = Application.WorksheetFunction.Max(1, startIndex - 10)
            endIndex = Application.WorksheetFunction.Min(endIndex + 10, Len(searchCell.Value))

            ' 앞뒤 10글자 추출
            surroundingText = Mid(searchCell.Value, startIndex, endIndex - startIndex + 1)

            ' 결과 변수에 값을 추가
            result = result & surroundingText & ", "
        End If
    Next i

    ' 결과가 비어있으면 "없음"으로 설정
    If result = "" Then
        result = "없음"
    Else
        ' 마지막에 추가된 쉼표와 공백 제거
        result = Left(result, Len(result) - 2)
    End If

    ' 결과 반환
    findx = result
End Function

공유

facebooktwitterpinterestbandkakao story
퍼머링크

댓글 0

댓글 쓰기

신고

"님의 댓글"

이 댓글을 신고 하시겠습니까?

삭제

"님의 댓글"

이 댓글을 삭제하시겠습니까?