Compare text in two columns and hilight the differences in another column

raghuram.star

Board Regular
Joined
Sep 5, 2012
Messages
102
Can you please help to compare text in two columns and hilight the differences in another column.:confused:

Example

Old Text (Col A)
New Text (Col B)Comparision (Col C)
It was the humans who was sent to Moon firstBut later they said it was animals which was sent to Moon First.
But later they said it was animals which (the humans who) was sent to Moon First.
Is it possible to compare the text in multiple lines

like this text is in seperate line

a cell in excel is free text8 and any one can tye any thing in it
Can it possible to compare the texts in multiple lines.

could it be like this text is in seperate line?

This is completely new line of text in the cell which has no trace in the old text

Each cell in excel is free text9 and any onebody could tye any thing in it.
Can (Is) it possible to compare the texts in multiple lines.

could it be like this text is in seperate lines?

This is completely new line of text in the cell which has no trace in the old text

Each (a) cell in excel is free text9 (text8) and anybody could (any one can) tye any thing in it.

<tbody>
</tbody>

Please help me.

I have below code by
Code:
Const redCIndex As Long = 3
Const blackCIndex As Long = 0

Sub CheckAgainstColumnA()
    Dim oneCell As Range
    With ThisWorkbook.Sheets("Sheet1").Range("A:A"): Rem adjust
        For Each oneCell In Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
            oneCell.Font.Color = blackCIndex
            oneCell.Offset(0, 1).Font.ColorIndex = blackCIndex
            Call highlightDifference(oneCell, oneCell.Offset(0, 1))
            Call highlightDifference(oneCell.Offset(0, 1), oneCell)
        Next oneCell
    End With
End Sub

Sub highlightDifference(refCell As Range, testCell As Range)
    Dim refString As String, testString As String
    Dim i As Long, startPoint As Long, newPoint As Long
    
    testCell.Font.ColorIndex = redCIndex
    
    refString = refCell.Text
    testString = testCell.Text
    startPoint = 1
    For i = 1 To Len(refString)
        newPoint = InStr(startPoint, testString, Mid(refString, i, 1))
        If newPoint <> 0 Then
            testCell.Characters(newPoint, 1).Font.ColorIndex = blackCIndex
            startPoint = newPoint + 1
        End If
    Next i
End Sub

I am a novice to VBA and I could not edit it for my need.

Please help me...
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Can the result be in below fashion, instead of having the result in new column as requed in above request?

Old Text (Col A)
New Text (Col B)
It was the humans who was sent to Moon firstBut later they said it was animals which was sent to Moon First.
Is it possible to compare the text in multiple lines

like this text is in seperate line

a cell in excel is free text8 and any one can tye any thing in it

This part of text is there in old text cell only. But this text part is there carryforwaded to new text. And again this is not the in new text cell
Can it possible to compare the texts in multiple lines.

could it be like this text is in seperate line?

This is completely new line of text in the cell which has no trace in the old text

Each cell in excel is free text9 and anybody could tye any thing in it.

But this text part is there carryforwaded to new text

<tbody>
</tbody>


Thank you
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,905
Members
449,478
Latest member
Davenil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top