'Letter by letter Comparison

I have 2 sets of data in two cells (A1 and B1) without any special character (.,/;:'"-@#$%^&*(){}[]) and also no space between words,

The problem is I need to compare both the cells and identify and highlight the difference.

For example :

(A1): howtobuilfmacroincludingthesecrria
(B1): howbuilfmacroincludingthesecriteria
  • in A1 ite is missing
  • and B1 to is missing

The macro should highlight ite in B1 and to in A1



Solution 1:[1]

it's very difficult to perform mutual checks because excel doesn't know the words. What does it words represent? You can do check on one column like this:

Sub CompareMacro()
Dim columnA As Integer
Dim columnB As Integer
Dim NumberOfCaracters As Integer
Dim f As Integer
f = 1
For numbuerOfRows = 1 To 5
    columnA = Len(Worksheets(1).Cells(numbuerOfRows, 1))
    columnB = Len(Worksheets(1).Cells(numbuerOfRows, 2))

    If columnA > columnB Then
        NumberOfCharacters = columnA
    Else
        NumberOfCaracters = columnB
    End If

    Dim columnALetters(3) As Variant

    For i = 1 To NumberOfCaracters

        If Mid(Worksheets(1).Cells(numbuerOfRows, 1), i, 1) = Mid(Worksheets(1).Cells(numbuerOfRows, 2), f, 1) Then                 
             f = f + 1
         Else
    Worksheets(1).Cells(numbuerOfRows, 1).Characters(i, 1).Font.Color = vbRed
        End If      
    Next i
Next numbuerOfRows
End Sub

Solution 2:[2]

You can use object and then use msword concept first A1 content in one and other in second and compare two of them any n no.of words is there it shows and highlight.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Prabhakar Reddy