Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Snowhare

엑셀 vba 셀의 특정 텍스트 찾아 색깔 설정 본문

카테고리 없음

엑셀 vba 셀의 특정 텍스트 찾아 색깔 설정

snowhare 2022. 1. 26. 13:55

엑셀 vba 셀의 특정 텍스트 찾아 색깔 설정

엑셀 셀안의 텍스트의 특정 단어나 문장을 색으로 표시해서 잘 보이게 하고 싶습니다. 엑셀 매크로를 조금 아신다면...
 

sub findStrColor()

dim strTest as String

dim strLen as String

dim pos as Integer

    strTest = "single failure" ' 색을 입히려는 단어

    strLen = Len(strTest)

For Each cell in Selection        ' 선택한 셀 범위에서 변경

    pos = Intr(1, cell, strTest, 1) ' 대소문자 구분하려면, 마지막의 1을 0으로

        if (pos > 0) Then

            cellLen = Len(cell.Text)

            Do

                cell.Characters(pos, strLen).Font.Color = vbRed ' 빨간색으로 설정

                pos = InStr(pos +1, cell, strTest, 1) ' 대소문자 구분 안함.

            Loop While ((pos > 0) And (strLen + pos - 1 <= cellLen))

        end If

Next

End Sub