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

특정 단어 찾기

  • 만조
  • 14
  • 0

Function findx(searchWord As String, searchCell As Range) As String
    Dim result As String
    Dim startIndex As Integer
    Dim endIndex As Integer
    Dim surroundingText As String

    ' 결과 및 초기 인덱스 설정
    result = ""
    startIndex = InStr(1, searchCell.Value, searchWord, vbTextCompare)

    ' 찾을 단어가 존재하는 경우
    If startIndex > 0 Then
        ' 찾은 단어의 앞뒤 10글자의 시작 및 끝 인덱스 계산
        endIndex = startIndex + Len(searchWord) - 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 = surroundingText
    End If

    ' 결과 반환
    findx = result
End Function

공유

facebooktwitterpinterestbandkakao story
퍼머링크

댓글 0

댓글 쓰기

신고

"님의 댓글"

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

삭제

"님의 댓글"

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