DianeDelRio
New Member
- Joined
- Oct 29, 2019
- Messages
- 4
Hello, I I am working on trying to find the differences between a string of words in selected cells. I attempted to use the Wordif function, and got the changes, however I would just like to format the changes in red.
For example
Currently Cells Show:
A1: The green dog likes to run .
B1: A green dog really likes to run sometimes.
Macro/VBA used Should Show:
A2: The green dog likes to run.
B2: A green dog really likes to run sometimes.
Or something of that nature. Essentially I would like to compare the two cell "versions" to spot the differences.
If you could assist with a macro that can format the color and show redacted words/ additional spaces added, that would be incredible.
P.S. Currently this is the macro I am using- it shows the differences, but leaves the words as "-", rather than just changing the font.
Please let me know if you need any further information.
Function WORDDIF(rngA As Range, rngB As Range) As String
Dim WordsA As Variant, WordsB As Variant
Dim ndxA As Long, ndxB As Long, strTemp As String
WordsA = Split(rngA.Text, " ")
WordsB = Split(rngB.Text, " ")
For ndxB = LBound(WordsB) To UBound(WordsB)
For ndxA = LBound(WordsA) To UBound(WordsA)
If StrComp(WordsA(ndxA), WordsB(ndxB), vbTextCompare) = 0 Then
WordsA(ndxA) = vbNullString
Exit For
End If
Next ndxA
Next ndxB
For ndxA = LBound(WordsA) To UBound(WordsA)
strTemp = strTemp & IIf(WordsA(ndxA) <> vbNullString, WordsA(ndxA), "-") & " "
Next ndxA
WORDDIF = Trim(strTemp)
End Function
For example
Currently Cells Show:
A1: The green dog likes to run .
B1: A green dog really likes to run sometimes.
Macro/VBA used Should Show:
A2: The green dog likes to run.
B2: A green dog really likes to run sometimes.
Or something of that nature. Essentially I would like to compare the two cell "versions" to spot the differences.
If you could assist with a macro that can format the color and show redacted words/ additional spaces added, that would be incredible.
P.S. Currently this is the macro I am using- it shows the differences, but leaves the words as "-", rather than just changing the font.
Please let me know if you need any further information.
Function WORDDIF(rngA As Range, rngB As Range) As String
Dim WordsA As Variant, WordsB As Variant
Dim ndxA As Long, ndxB As Long, strTemp As String
WordsA = Split(rngA.Text, " ")
WordsB = Split(rngB.Text, " ")
For ndxB = LBound(WordsB) To UBound(WordsB)
For ndxA = LBound(WordsA) To UBound(WordsA)
If StrComp(WordsA(ndxA), WordsB(ndxB), vbTextCompare) = 0 Then
WordsA(ndxA) = vbNullString
Exit For
End If
Next ndxA
Next ndxB
For ndxA = LBound(WordsA) To UBound(WordsA)
strTemp = strTemp & IIf(WordsA(ndxA) <> vbNullString, WordsA(ndxA), "-") & " "
Next ndxA
WORDDIF = Trim(strTemp)
End Function