Compare two sentences and show changes

Rafaelete

New Member
Joined
Feb 2, 2022
Messages
14
Office Version
  1. 2007
Platform
  1. Windows
I´m trying to compare two sentences in differente cells and show the difference in red.

I´m using a code that has a problem. Is comparing the position of each letter. When it finds a difference it shows it in red which is fine. The problem is that if a word is changed with a word with a different amount of letters, the rest of the sentence also appears in red.

As an example:

1655896024153.png


In this picture you can see that after a word is found, the rest of the words also appear as different even though they are the same.

This is the code that I´m currently using:

Sub Compare()

For i = 1 To Len(ActiveSheet.Range("F1").Value)

If (ActiveSheet.Range("F1").Characters(i, 1).Text <> ActiveSheet.Range("G1").Characters(i, 1).Text) Then

ActiveSheet.Range("F1").Characters(i, 1).Font.Color = RGB(255, 0, 0)

End If

Next i

End Sub


Also, this code is one working on the selected cell, I need it to work with the entire column (F and G).

Thanks in advanced
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,737
Messages
6,126,576
Members
449,318
Latest member
Son Raphon

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