728x90
반응형
Sub HighlightDifferences()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long, j As Long
Dim strA As String, strB As String
Dim minLen As Long
Set ws = ActiveSheet ' 현재 활성 시트
' A열 기준 마지막 행 찾기
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' 각 행마다 비교
For i = 1 To lastRow
strA = ws.Cells(i, 1).Value
strB = ws.Cells(i, 2).Value
minLen = Application.Min(Len(strA), Len(strB))
' 기존 서식 초기화
ws.Cells(i, 1).Characters.Font.Color = vbBlack
ws.Cells(i, 1).Characters.Font.Bold = False
ws.Cells(i, 2).Characters.Font.Color = vbBlack
ws.Cells(i, 2).Characters.Font.Bold = False
' 문자열 비교
For j = 1 To minLen
If Mid(strA, j, 1) <> Mid(strB, j, 1) Then
' A열 글자 강조
ws.Cells(i, 1).Characters(j, 1).Font.Color = vbRed
ws.Cells(i, 1).Characters(j, 1).Font.Bold = True
' B열 글자 강조
ws.Cells(i, 2).Characters(j, 1).Font.Color = vbRed
ws.Cells(i, 2).Characters(j, 1).Font.Bold = True
End If
Next j
Next i
End Sub
엑셀의 vba에 (alt+f11) 모듈 삽입 해서 위의 스크립트를 넣고 닫은 후에
f8넣고 실행하면 된다.
728x90
반응형