View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
DJS DJS is offline
external usenet poster
 
Posts: 31
Default compare strings - highlight characters which are different

Thanks Andrew, I just added an "For Each, Next" loop to carry me through all
valid rows & a count of incorrect characters in an adjoining column and it
works great.
Much Appreciated!

"Andrew Taylor" wrote:

It's certainly possible to colour individual characters. The
following code will work on I1 and I2 as long as the values
are constant strings, not numbers or the results of formulas.

Option Explicit
Sub HighlightDifferences()
Dim r1 As Range, r2 As Range, i As Integer
Set r1 = Range("I1")
Set r2 = Range("J1")

For i = 1 To Len(r1.Value)
If Mid(r1.Value, i, 1) = Mid(r2.Value, i, 1) Then
r1.Characters(i, 1).Font.ColorIndex = xlAutomatic
Else
r1.Characters(i, 1).Font.Color = vbRed
End If
Next
End Sub





stevebriz wrote:
DJS,
I don;t think it is possible to color characters with a different color
in the same cell.
so do you have another option?

DJS wrote:
Yes, they should be 17 alpha-numeric characters.

"stevebriz" wrote:

Are the string lengths the same in both column I and J for each row?
DJS wrote:
Hello~
I need some assistance in writing a macro which could compare each
alpha-numeric character in each row of column I & J and hightlight (via font
color) the characters of column I which are different, then move to the next
row. I need to run the macro on every row until i come to a blank row.
Any help greatly appreciated.

Thanks in advance,
Don