메인 컨텐츠로 가기

텍스트를 찾아서 바꾸고 Excel에서 서식을 유지하는 방법은 무엇입니까?

문서 찾기 교체 보존 형식 1
문서 찾기 교체 보존 형식 2
찾기 및 바꾸기 기능은 특정 값을 찾아 다른 값으로 대체해야 할 때 강력하고 유용합니다. 그러나 셀 범위가 있고 일부 셀에 다른 서식 값이 포함 된 경우. 이 경우 찾기 및 바꾸기 기능으로 값을 찾고 바꾸려면 아래 스크린 샷과 같이 셀의 값 서식이 깨집니다. Excel에서 찾아서 바꾸는 동안 각 셀의 값 서식을 어떻게 유지할 수 있습니까?

매크로 코드로 서식 유지 찾기 및 바꾸기

화살표 블루 오른쪽 거품 매크로 코드로 서식 유지 찾기 및 바꾸기

다른 방법은 없지만 매크로 코드를 사용하면 텍스트를 찾아 바꾸고 서식을 유지할 수 있습니다.

1. 프레스 Alt + F11 키를 눌러 응용 프로그램용 Microsoft Visual Basic 창.

2. 클릭 끼워 넣다 > 모듈, 아래 코드를 스크립트에 붙여 넣으십시오.

VBA : 서식 유지 찾기 및 바꾸기

Sub CharactersReplace(Rng As Range, FindText As String, ReplaceText As String, Optional MatchCase As Boolean = False)
  'UpdatebyExtendoffice20160711
    Dim I As Long
    Dim xLenFind As Long
    Dim xLenRep As Long
    Dim K As Long
    Dim xValue As String
    Dim M As Long
    Dim xCell As Range
    xLenFind = Len(FindText)
    xLenRep = Len(ReplaceText)
    If Not MatchCase Then M = 1
    For Each xCell In Rng
        If VarType(xCell) = vbString Then
            xValue = xCell.Value
            K = 0
            For I = 1 To Len(xValue)
              If StrComp(Mid$(xValue, I, xLenFind), FindText, M) = 0 Then
                xCell.Characters(I + K, xLenFind).Insert ReplaceText
                K = K + xLenRep - xLenFind
              End If
            Next
        End If
    Next
End Sub

Sub Test_CharactersReplace()
    Dim xRg As Range
    Dim xTxt As String
    Dim xCell As Range
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
      xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
      xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Application.InputBox("Select a range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    Call CharactersReplace(xRg, "KK", "Kutools", True)
End Sub

 

문서 찾기 교체 보존 형식 5

3. 프레스 F5 키를 누르면 찾고 바꿀 범위를 선택할 수있는 대화 상자가 나타납니다. 스크린 샷을 참조하십시오.
문서 찾기 교체 보존 형식 6

4. 확인을 클릭하면 선택한 셀의 특정 문자열이 다른 문자열로 바뀌고 서식이 유지됩니다.
문서 찾기 교체 보존 형식 4

: 코드에서  KK 찾고자하는 문자열이고 쿠툴 바꿀 문자열입니다. 필요에 따라 변경할 수 있습니다.

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
Comments (6)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Thanks, it has worked wonders for me. I needed to replace a colon with a newline character, but all the text before the colon should stay bold caption, where the rest of it should be left in regular. It has worked and abridged my work today.
Though I didn't try with cells with more than 255 characters, as it seems to be an issue with other people commenting.
Rated 5 out of 5
This comment was minimized by the moderator on the site
Can you clarify if there is a solution that works in cells with more than 255 characters, or is this a limitation of Excel? Does your add-in support cells with more than 255 characters that contain formatting?
This comment was minimized by the moderator on the site
Same Question as John Birk i need a workaround with Cells that have more then 255 signs.
This comment was minimized by the moderator on the site
The method only work while characters less than 255 digits.
This comment was minimized by the moderator on the site
I am getting syntax error in VBA
This comment was minimized by the moderator on the site
I tried your solution on a cell that is over 255 characters long and nothing changes. Is there a workaround for this case?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations